unsupported operand types in BAO/Navigation.php, orderByWeight
Hi,
when trying out if a Wordpress+Civi test instance would survive a PHP upgrade to 8.0, I found that the CiviCRM menu had gone missing. It turned out that a fatal PHP error occured in the AJAX call that retrieves the menu structure. It originated in line 323 of CRM/Core/BAO/Navigation.php, which is in the orderByWeight function:
return $a['attributes']['weight'] - $b['attributes']['weight'];
Perhaps PHP 8 is treating such issues more seriously than 7 – sorry but I simply don’t know. In any case, I was able to overcome this by adding explicit type casts:
return (int) $a['attributes']['weight'] - (int) $b['attributes']['weight'];
This was complete guesswork and maybe I should have cast to float instead – again, I don’t know. But I thought this might be worth reporting so you can decide how to best safeguard that line. For now I am happy to have my menu back with this temporary and local patch.
By the way, this was observed in version 5.54.1 but I notice that the line is unchanged in the master, 5.55 and 5.56 branches.