奇怪的 php 错误
我有以下代码:
var_dump($cumulitive);
$y_axis_max = max($cumulitive)*1.3;
var_dump($y_axis_max);
它输出以下内容:
array(16) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
[4]=>
int(0)
[5]=>
int(0)
[6]=>
int(0)
[7]=>
int(0)
[8]=>
int(0)
[9]=>
int(0)
[10]=>
int(0)
[11]=>
int(4)
[12]=>
int(4)
[13]=>
int(4)
[14]=>
int(9)
[15]=>
int(9)
}
float(NAN)
如您所见, $y_axis_max 给出 NAN。所以我尝试这样做:我重新启动 WampServer。现在可以了。我刷新浏览器。再次工作。再次刷新浏览器。现在它不起作用了,如果不重新启动 Apache,我就无法让它再次工作。从第三个请求开始,它停止工作。
它曾经工作得很好。然后我改变了一些事情。具体来说,我修改了我的应用程序以在几个地方使用 DateTime 类。但这不应该使这个奇怪的错误发生。关于如何调试这个有什么想法吗?
如果我连续两次调用 $y_axis_max = .. 代码行,那么我会得到 $y_axis_max:
float(@.7)
这到底是什么?
编辑:似乎较早调用 DateTime::diff 会导致错误。有什么解决办法吗?
I have the following code:
var_dump($cumulitive);
$y_axis_max = max($cumulitive)*1.3;
var_dump($y_axis_max);
It outputs the following:
array(16) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
[4]=>
int(0)
[5]=>
int(0)
[6]=>
int(0)
[7]=>
int(0)
[8]=>
int(0)
[9]=>
int(0)
[10]=>
int(0)
[11]=>
int(4)
[12]=>
int(4)
[13]=>
int(4)
[14]=>
int(9)
[15]=>
int(9)
}
float(NAN)
As you can see, $y_axis_max is giving NAN. So I try this: I restart WampServer. It works now. I refresh the browser. Works again. refresh the browser again. Now it doesn't work, and I can't get it to work again without restarting Apache. From the 3rd request on it stops working.
It USED to work just fine. Then I changed some things. Specifically, I modified my app to use the DateTime class in a few places. But that shouldn't make this strange error occur. Any ideas on how to debug this?
If I call the $y_axis_max = .. line of code twice in a row, then I get this for $y_axis_max:
float(@.7)
What the heck is that?
EDIT: Seems that calling DateTime::diff earlier causes the error. Any workaround ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
max() 适用于数组。看起来您的代码中存在某种形式的损坏。如果数组中的元素之一是 NAN,您将得到此结果。尝试在服务器上测试较小的脚本以隔离问题。
max() will work on arrays. Looks like you have some form of corruption in your code. If one of the elements in the array is a NAN you will get this result. Try testing a smaller script on your server in order to isolate the problem.
似乎较早调用 DateTime::diff 会导致错误。我只是使用了一种解决方法,所以没有使用它。
Seems that calling DateTime::diff earlier causes the error. I just used a work-around so not to use it.