Rewriting usort function because of fatal error (PHP bug)
Posted
by
Lionel
on Stack Overflow
See other posts from Stack Overflow
or by Lionel
Published on 2013-10-25T15:52:13Z
Indexed on
2013/10/25
15:53 UTC
Read the original article
Hit count: 231
The two following usort functions throw fatal error Base lambda function for closure not found in our productive environment (PHP 5.4). This seems to be a known PHP bug that should be fixed by now (https://bugs.php.net/bug.php?id=52144), but it still occurs for us.
Anyway, we unfortunately don't have time to figure out what's wrong with our PHP configurations etc. We would like to rewrite these two functions without the use of anonymous functions, so that the error doesn't occur anymore.
Ordering of a multidimensional array ($array) by value of key "position":
usort($array, function($a, $b) { return $a['position'] - $b['position']; });
Ordering of a multidimensional array ($array) according to the order of a second array ($position_order):
usort($array, function($a, $b) use($position_order) { return (isset($position_order[$a['ftid']]) ? ($position_order[$a['ftid']] - $position_order[$b['ftid']]) : 1); });
Especially the latter causes some headache, as we don't know how to pass the "outside" array $position_order.
© Stack Overflow or respective owner