简体   繁体   中英

Strange Callback Error PHP 5.4.30

I have the same exact PHP file on our development, and production servers. Both servers are running the same version of PHP, same modules, same interpreter, etc. Only the development server runs the code successfully. I have no idea what's causing this. I would normally chalk this up to a PHP versioning discrepancy, but that's not the case.

Both servers are running PHP 5.4.30.

Here is the code in question:

$inputArray = array('Tuesday' => null, 'Friday' => null, 'Monday' => null, 'Thursday' => null, 'Wednesday' => null);

$desiredIndexOrder = array('Monday' => 5, 'Tuesday' => 4, 'Wednesday' => 3, 'Thursday' => 2, 'Friday' => 1);

uksort($inputArray, function($a, $b) use ($desiredIndexOrder) {
    return $desiredIndexOrder[$a] > $desiredIndexOrder[$b] ? -1 : 1;
});

echo print_r($inputArray);

Development output (Correct):

Array ( [Monday] => [Tuesday] => [Wednesday] => [Thursday] => [Friday] => ) 1

Production Output:

Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in /home/friendso/public_html/test.php on line 9 Array ( [Tuesday] => [Friday] => [Monday] => [Thursday] => [Wednesday] => ) 1

Writing the callback as an actual function fixes the issue, but I'm curious as to what could cause this.

As Sammitch pointed out in a comment to my original question, eAccelerator was indeed the issue (not sure exactly why). To disable eAccelerator, I made these changes in my php.ini file, and restarted Apache.

eaccelerator.enable 0
eaccelerator.optimizer 0

The code now works as intended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM