【发布时间】:2013-08-22 22:05:03
【问题描述】:
好的,所以我在玩堆栈溢出循环的想法。我输入了以下代码并在 Google Chrome 中获得了一张可爱的小图片(他们对 500 内部错误的回答,这对 Google 来说没有帮助!)。这是意料之中的事。
代码集 #2
<?php
for($x=-1;$x<=3;$x++){
echo $x/0.">";
}
?>
通过检查我找到的标题:
http://server.domain/overflow.php
GET /overflow.php HTTP/1.1
Host: server.domain
User-Agent: Browser
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0
HTTP/1.0 500 Internal Server Error
Date: Thu, 22 Aug 2013 21:51:30 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8
我得到了上面的代码,因为我实际上想知道除以零以及 PHP 是如何处理它的。我编写了下面的代码来尝试触发结果,但没有得到我所期望的。问题不是从下面的代码中得到500 internal server error,而是得到别的东西......我希望服务器抛出错误的NULL。
代码集 #1
<?php
for($x=-1;$x<=3;$x++){
echo $x/$x.">";
}
?>
输出
1>>1>1>1>
问题
既然我除以零,为什么第一段代码不会导致 500 内部服务器错误? 1/1=1,1/0=500 Error,0/0=Null
【问题讨论】:
-
检查您的服务器日志。当您收到服务器错误时,您会在那里找到它们。
-
我从第二个代码集中看到了 500 错误。我从一开始就期待它,但只得到一个 NULL。
-
好吧,你可能也有兴趣了解运算符优先级php.net/manual/en/language.operators.precedence.php
-
这个问题似乎离题了,因为它是关于启用错误报告的。
-
ini_set('display_errors',1); error_reporting(E_ALL);创造奇迹
标签: php divide-by-zero