custom private message block generates error I created a block to generate a private message link to send a message to all the users of a group. I use the php code as the text format on the block body.

&lt;?php
$group = og_context();
$og_id = $group-&gt;gid;

$query = db_select("og_membership", "ogm");
$query-&gt;condition("ogm.gid", $og_id, "=");
$query-&gt;fields("ogm", array("entity_type", "etid"));
$result = $query-&gt;execute();

$result_tmp = $result-&gt;fetchAll();
$recipients = array();

foreach($result_tmp AS $tmem)
{
$recipients[] =  user_load($tmem-&gt;etid);
}

echo '&lt;a href=/';
echo privatemsg_get_link($recipients,$account = array(),$subject = NULL);
echo '&gt;Send message to ehood members&lt;/a&gt;';
?&gt;


When I use this, It created me a notice message saying - 


Notice: Trying to get property of non-object in privatemsg_user_access() (line 335 of /sites/all/modules/privatemsg/privatemsg.module).
Notice: Trying to get property of non-object in privatemsg_user_access() (line 335 of /sites/all/modules/privatemsg/privatemsg.module).



Although it generated the link, It creates the error. I think its somehow related to how $account is mentioned ?

i tried to send global $user instead of $account, but still creates the same error.
In this case, the problem is that privatemsg_get_link() uses array() as default value for $account, but then uses the following code.

  if ($account == NULL) {
    global $user;
    $account = $user;
  }


The function should use NULL as default value for $account, in the same way user_access() does.

function user_access($string, $account = NULL) {
  global $user;

  if (!isset($account)) {
    $account = $user;
  }

  // ...
}


The error message you see is because the function tries to access $account-&gt;uid when $account is an empty array. An array doesn't have properties, and that is what the message is saying.
As the function is passing that value to user_access(), the same error would be raised from user_access(), which check the value of $account-&gt;uid, and for which an empty array is not the correct value to pass to its $account parameter, which requires an user object, or NULL.

It's fine to use the default values a function has, but you should check what the function does when it gets the default values for its parameters. 

It is wrong to call a function as privatemsg_get_link($recipients, $account = array(), $subject = NULL) when you want to use the default values for its parameters. Just call the function as privatemsg_get_link($recipients). With your code, you are setting $account to an empty array, and passing $account as parameter.
PHP doesn't have named parameters, but only positional parameters. If it had named parameters, it would be possible to call a function indifferently as functioname(34, param3 = 4, param2 = 12), or functioname(34, param2 = 12, param3 = 4).