简体   繁体   English

奇怪的回调错误PHP 5.4.30

[英]Strange Callback Error PHP 5.4.30

I have the same exact PHP file on our development, and production servers. 我在开发和生产服务器上具有相同的PHP文件。 Both servers are running the same version of PHP, same modules, same interpreter, etc. Only the development server runs the code successfully. 这两个服务器都运行相同版本的PHP,相同的模块,相同的解释器等。只有开发服务器才能成功运行代码。 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. 我通常会将此归结为PHP版本差异,但事实并非如此。

Both servers are running PHP 5.4.30. 两台服务器都运行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 数组([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 警告:uksort()期望参数2是有效的回调,在第9行数组/home/friendso/public_html/test.php中没有给出数组或字符串([星期二] => [星期五] => [星期一] => [星期四] => [星期三] =>)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). 正如Sammitch在对我的原始问题的评论中指出的那样,eAccelerator确实是问题所在(不确定确切原因)。 To disable eAccelerator, I made these changes in my php.ini file, and restarted Apache. 要禁用eAccelerator,我在php.ini文件中做了这些更改,然后重新启动了Apache。

eaccelerator.enable 0
eaccelerator.optimizer 0

The code now works as intended. 该代码现在可以按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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