Cannot use object of type stdClass as array I'm very new to Drupal and I'm receiving the error:

Cannot use object of type stdClass as array

in the following code:

$toolbar = $page['toolbar'];
foreach( $toolbar['menu_menu-smart-resources'] as $id =&gt; $object ) {
  $toolbar['menu_menu-smart-resources'][$id]['#localized_options']['attributes']['data-role'] = 'foo';      
}
print render($page['toolbar']);


Can someone help.
You are able to change menu attributes using Menu Attributes module . If any customization is needed on top of that then you can follow the below process.

You can able to override theme links using theme_menu_link in template.php. Follow below step to override.


Go to your active theme folder might be in sites/all/theme or if you are using default theme then themes folder
Go to the active theme folder
Look for template.php
Override theme_menu_link by copy pasting entire function and replacing theme with your theme name.
Do your changes inside function wherever necessary!