usort():数组已由用户比较功能修改 [英] usort(): Array was modified by the user comparison function

查看:59
本文介绍了usort():数组已由用户比较功能修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,可以在我们的Linux服务器上正常运行,但是在使用PHP 5.3的Zend Community Edition Server在Mac OS上运行时,出现错误:

I have a web application that runs fine on our Linux servers but when running on Mac OS with the Zend Community Edition Server using PHP 5.3 we get the error:

usort():数组已通过用户比较功能修改

usort(): Array was modified by the user comparison function

页面第一次加载时(页面在Linux服务器上翻页并加载大约需要2分钟,页面加载时间为1秒).

every time a page loads for the first time (it takes about 2 minutes for a page to tick over and load, on the linux servers the page loads in 1 second).

让其他任何人都经历过此事或对如何解决该问题有任何想法,我曾尝试过PHP和Apache内存设置,但是没有运气.

Has anyone else experienced this or has any idea how I can fix the problem, I have tried playing around with PHP and Apache memory settings with no luck.

推荐答案

即使您不更改数组,也存在可能导致此警告的PHP错误.

There is a PHP bug that can cause this warning, even if you don't change the array.

简短版本,如果有任何PHP调试函数检查sort数组,它们将更改引用计数并欺骗usort()认为您已更改数据.

Short version, if any PHP debug functions examine the sort array, they will change the reference count and trick usort() into thinking you've changed the data.

因此,您可以通过在sort函数(或从中调用的任何代码)中执行以下任何操作来获得该警告:

So you will get that warning by doing any of the following in your sort function (or any code called from it):

  • 在任何排序数据上调用var_dumpprint_r
  • 致电debug_backtrace()
  • 引发异常-任何异常-甚至只是创建一个异常
  • calling var_dump or print_r on any of the sort data
  • calling debug_backtrace()
  • throwing an exception -- any exception -- or even just creating an exception

该错误影响所有PHP 5版本> = 5.2.11,但不影响PHP> =7.请参阅

The bug affects all PHP 5 versions >= 5.2.11 but does not affect PHP >= 7. See the bug report for further details.

据我所知,唯一的解决方法是不要那样做"(对于异常情况有点难),或者使用错误抑制运算符@usort()来忽略所有错误.

As far as I can see, the only workaround is either "don't do that" (which is kind of hard for exceptions), or use the error suppression operator @usort() to ignore all errors.

这篇关于usort():数组已由用户比较功能修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆