How do I access the node's uid in hook_node_access()? I have implemented hook_node access so that two users cannot view each other's posts if they do not have the right permission (I implemented the permission in hook_permission). I use a comparison with $node->uid as follows:

 function mymodule_node_access( $node, $op, $account)
 {
   global $user;                                                                                                                                                       
   $type = is_string($node) ? $node : $node-&gt;type;

   switch($type)
   {
    case "myCustomType":

      if ( ($user-&gt;uid != $node-&gt;uid) &amp;&amp; !user_access("view other's posts"))
       {
              return NODE_ACCESS_DENY;

       }
       break;

   }

}


Everything works fine but I do get the following warning:


  Notice: Trying to get property of non-object in mymodule_node_access(). 


This is caused by this: $node->uid. Drupal complains that $node is a  not a stdobject (it seems to actually be string containing the node's type). Yet the code still works which I do not understand why. 

What is the proper way to access the node's uid from hook_node_access?
The $node parameter is


  Either a node object or the machine name of the content type on which to perform the access check.


When that hook is invoked with the create op, there's no node object available, so $node is a string. 

You're already handling that bit, but you're missing a check on the $op parameter. The reason it's working is because when your function is invoked with the op you're trying to target (probably view), $node is an object and has a uid property. 

With your current code, you'll get one of those notices every time someone other than user 1 tries to create a node, because $node is not an object.

Try re-working your code like this:

function mymodule_node_access( $node, $op, $account)
 {
   if ($op == 'create') {
     $type = $node;
     // You can be reasonably sure that $account is the user who's trying to create the node here.
     // You'll probably want to ignore this bit and check $op specifically for the 
     // actions you're looking for; this is just here to show the workflow.
   }
   else {
     if ($node-&gt;type == 'myCustomType') {
       // Be sure to use the $account var here, not the global $user object
       if ( ($account-&gt;uid != $node-&gt;uid) &amp;&amp; !user_access("view other's posts", $account)) {
       return NODE_ACCESS_DENY;
     }
   }

   return NODE_ACCESS_IGNORE;