Menu rebuild causes:
Object of class stdClass could not be converted to int in _menu_router_build() - line 3370
error when using some contrib modules such as nodequeue.
This is due to a bug in the behavior of
array_multisort(), which is used in _menu_navigation_links_rebuild().
array_multisort() keeps sorting by all dimensions of the array, and if any of the (sub)-children are objects it will trigger a notice that it cannot compare them to other types.
Here is a generic PHP script that will trigger this error:
$sort['A'] = 2;
$sort['B'] = 1;
$sort['C'] = 1;
$menu['A'] = 0;
$menu['B'] = (object) array(0);
$menu['C'] = 0;
array_multisort($sort, SORT_NUMERIC, $menu);
Fix the sorting of menu items to not use
array_multisort() but just a normal
asort(). A patch implementing this change is in . A test that reproduces the bug is included in the patch.
A workaround for modules that trigger this error is to change the order of arguments in
hook_menu() declarations. See for example this commit to fix this bug in the nodequeue module, and .
- Adjust patch for changes from
- Evaluate the impact this change could have on performance, as
array_multisort()may have been chosen for performance reasons.
- For the related issue of the side effects of passing cached objects to the menu system, see .
User interface changes
Original report by tekante
When doing a minimal install with Drupal 7 Beta2, the above error is observed after enabling the nodequeue module when using the head revision and patches http://drupal.org/files/issues/nodequeue-d7-db-insert-errors-fix.patch and http://drupal.org/files/issues/nodequeue-941558-16.patch.
Why am I not filing this in the nodequeue queue? I don't believe the error is due to anything nodequeue is doing wrong based on the variety of things that resolve the error. Comparing its info to that of another item (admin/structure/types does not show any obvious errors). There is an issue filed related to this but I wanted to bring it to the attention of the menu system maintainer 
Attached is a file containing a serialized dump of the $sort and $menu states along with comments about various manipulations to the data that result in the error disappearing.
The error disappears in the following conditions:
1. Unsetting arbitrary admin/structure/nodequeue menu entry sub keys
2. Adding a SORT_STRING parameter as the 4th argument to the array_multisort call on line 3370
3. Unsetting an arbitrary subkey of another menu entry (admin/structure/types in the attached file)
My PHP versions are
PHP 5.2.13 (cli) (built: Mar 7 2010 09:15:25)
PHP 5.3.2 (cli) (built: Aug 7 2010 00:04:41)
FAILED: [[SimpleTest]]: [MySQL] 41,556 pass(es), 1 fail(s), and 0 exception(s). View
FAILED: [[SimpleTest]]: [MySQL] 41,127 pass(es), 1 fail(s), and 0 exception(s). View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-menu-int-972536-86.patch. Unable to apply patch. See the log in the details link for more information. View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-menu-int-972536-83-D7.patch. Unable to apply patch. See the log in the details link for more information. View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-menu-int-972536-81.d7.patch. Unable to apply patch. See the log in the details link for more information. View