Error message - Trying to get property of non-object i'm getting a notice


  Error message - Trying to get property of non-object


here's my function:

&lt;?php
function func()
{
        $node = menu_get_object();
        global $user;
        if ($node-&gt;type == 'hall' &amp;&amp;
            in_array('instructor', array_values($user-&gt;roles)))
        {
            return " hall-instructor ";
        }
}
?&gt;
You need to check what node_get_object() returns since it could not return an object. This is particularly true when the user is not watching a node page, but even in the case the viewed page is a node one, the function could not return an object. This is why Drupal code always check the returned value.

function book_page_alter(&amp;$page) {
  if (($node = menu_get_object()) &amp;&amp; !empty($node-&gt;book['bid'])) {
    $active_menus = menu_get_active_menu_names();
    $active_menus[] = $node-&gt;book['menu_name'];
    menu_set_active_menu_names($active_menus);
  }
}




// template_preprocess_page()
if ($node = menu_get_object()) {
  $variables['node'] = $node;
}




// template_preprocess_html()
// If on an individual node page, add the node type to body classes.
if ($node = menu_get_object()) {
  $variables['classes_array'][] = drupal_html_class('node-type-' . $node-&gt;type);
}