Undefined property error in custom module I am getting errors on specific pages of my drupal site pointing specifically to this line..

if (is_object($argument) &amp;&amp; in_array($router_item['page_arguments'][$key]-&gt;type, array('article', 'page'))) {


what could be the problem? Here's the complete error and function.

Notice: Undefined property: stdClass::$type in custommodule_menu_local_tasks_alter().

function custommodule_menu_local_tasks_alter(&amp;$data, $router_item, $root_path) {
  foreach ($router_item['page_arguments'] as $key =&gt; $argument) {
    if (is_object($argument) &amp;&amp; in_array($router_item['page_arguments'][$key]-&gt;type, array('article', 'page'))) {
      foreach ($data['tabs'][0]['output'] as $key =&gt; $value) {
        if (($value['#link']['path'] == 'node/%/edit'||'node/%/view') &amp;&amp; (!user_access('administer nodes'))){
          unset($data['tabs'][0]['output'][$key]);
        }
      }
    }
  }
}


Edit:
There are similar error in following line..

foreach ($data['tabs'][0]['output'] as $key =&gt; $value) {


--Notice: Undefined offset: 0 in custommodule_menu_local_tasks_alter() (line 59 of...)
--Warning: Invalid argument supplied for foreach() in custommodule_menu_local_tasks_alter() (line 59 of ...).
Most likely  $router_item['page_arguments'][$key]->type is undefined.

Try with :

if (is_object($argument) &amp;&amp; isset($router_item['page_arguments'][$key]-&gt;type) &amp;&amp; in_array($router_item['page_arguments'][$key]-&gt;type, array('article', 'page'))) {


Same thing for that foreach loop. Just add an if isset() before that loop and you'll be ok.

if (isset($data['tabs'][0]['output']) ) {
    foreach ($data['tabs'][0]['output'] as $key =&gt; $value) {
        ....