所以,我当前的网页上确实没有任何错误,但我希望能够在弹出时看到错误,而不是HTTP 500错误页面.我google了一下,并认为添加这两行将解决所有问题.
ini_set('display_errors', 'On');
error_reporting(E_ALL);
Run Code Online (Sandbox Code Playgroud)
注意:我无法访问php.ini文件,因为我正在使用我的学校帐户的服务器.
所以我在页面顶部介绍了一个bug(在$ buggy之后没有分号):
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy
$x = 4 + 2;
...
Run Code Online (Sandbox Code Playgroud)
但是,我只是收到服务器错误:
"该网站在检索http://mywebpage.com/时遇到错误.可能是因为维护失败或配置不正确."
有任何想法吗?
编辑:
我重新配置了我的代码:
<?php
include_once 'database/errorSettings.php';
?>
<?php
$buggy // whoops
$x = 4 + 2;
...
Run Code Online (Sandbox Code Playgroud)
errorSettings.php如下:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
Run Code Online (Sandbox Code Playgroud)
但它仍然无效...错误的重新配置方式?
dec*_*eze 14
你有什么是解析错误.在执行任何代码之前抛出这些.在执行任何代码之前,需要完整地解析PHP文件.如果您正在设置错误级别的文件中存在解析错误,则在抛出错误时它们不会生效.
将文件分成较小的部分,例如在一个文件中设置错误级别,然后在include另一个包含实际代码(和错误)的文件中设置,或者使用php.ini或.htaccess指令在PHP外部设置错误级别.
Nic*_*ark 13
您需要在.htaccess文件中设置error_reporting值.由于存在解析错误,因此它永远不会在PHP代码中运行error_reporting()函数.
在.htaccess文件中尝试此操作(假设您可以使用一个):
php_flag display_errors 1
php_value error_reporting 30719
Run Code Online (Sandbox Code Playgroud)
我认为30719对应于E_ALL,但我可能错了.
编辑更新: http ://php.net/manual/en/errorfunc.constants.php
int error_reporting ([ int $level ] )
---
32767 E_ALL (integer)
All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
Run Code Online (Sandbox Code Playgroud)
小智 5
加上上面说的deceze.这是一个解析错误,因此为了调试解析错误,请在名为debugSyntax.php的根目录中创建一个新文件.把它放进去:
<?php
/////// SYNTAX ERROR CHECK ////////////
error_reporting(E_ALL);
ini_set('display_errors','On');
//replace "pageToTest.php" with the file path that you want to test.
include('pageToTest.php');
?>
Run Code Online (Sandbox Code Playgroud)
运行debugSyntax.php页面,它将显示您选择测试的页面的解析错误.