不显示 PHP 错误
我已经将问题归结并使其清晰,以便您可以更轻松地帮助我。
我有一个非常简单的代码:
<?php
echo "Hello world";
?>
运行得很好。
如果我运行以下代码(解析错误),我不会收到任何错误,但仍然显示文本“Hello world”:
<?php
echo "Hello world";
piwejfoiwjefoijwef
?>
如果我将解析错误放在代码之前,它不会显示“Hello world”:
<?php
piwejfoiwjefoijwef
echo "Hello world";
?>
当我打印 phpinfo 时(在同一文件,同一目录中)我有以下设置: 显示错误打开 显示启动错误打开 error_reporting 1
如果我尝试在脚本内设置错误报告并使用以下代码运行它,我仍然不会收到任何错误或警告,但会显示文本“Hello world”:
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', '1');
echo "Hello world";
owieufpowiejf
?>
我的 php.ini 文件具有以下值(并且我已重新启动 Apache):
error_reporting = E_ERROR & ~E_DEPRECATED
display_errors = On
display_startup_errors = On
我正在 Amazon AMI 上和 64 位 AWS EC2 上运行 Apache / PHP / MySQL。我对服务器配置不太了解。当我转换到亚马逊服务器时,错误就开始了。除了错误报告之外,服务器和 Apache/PHP 运行完美。
请指导我如何解决该问题。
谢谢!
I've boiled down the problem and made it clean so that it hopefully will be easier for you to help me.
I have a very simple code:
<?php
echo "Hello world";
?>
This runs perfectly fine.
If I run the following code (parse error) I do not get any errors but the text "Hello world" is still displayed:
<?php
echo "Hello world";
piwejfoiwjefoijwef
?>
If I place the parse error before the code it does however not display "Hello world":
<?php
piwejfoiwjefoijwef
echo "Hello world";
?>
When I print phpinfo (in the same file, same directory) I have the following settings:
display_errors On
display_startup_errors On
error_reporting 1
If I try to also set the error reporting inside the script and run it with the following code I still do not get any errors or warning but the text "Hello world" is displayed:
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', '1');
echo "Hello world";
owieufpowiejf
?>
My php.ini file has the following values (and I have restarted Apache):
error_reporting = E_ERROR & ~E_DEPRECATED
display_errors = On
display_startup_errors = On
I am running Apache / PHP / MySQL on the Amazon AMI with on a 64-bit AWS EC2. I am not that knowledgeable with server configurations. The errors started when I transitioned to the Amazon server. Besides error reporting the server and Apache/PHP runs flawlessly.
Please guide me in what I can do to fix the problem.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在包含语法错误的同一脚本中调用
error_reporting()
永远不会起作用。特别是此脚本不会给您带来任何语法错误,因为它不包含任何语法错误。它只是一个
echo
语句和第二行中的一个简单常量。可以在?>
之前省略尾随分号,如果尚未关闭,您会收到通知。同样,您没有在其他测试中启用
E_NOTICE
。Calling
error_reporting()
in the same script that contains the syntax error is never going to work.This script in particular does not get you any syntax error, because it does not contain any syntax error. It's just an
echo
statement and a bare constant in the second line. The trailing semicolon can be omitted right before the?>
You would get a notice, if it hadn't been turned off. Again, you didn't enable
E_NOTICE
in your other test.那是一个通知。
揭示它。
我使用的代码:
输出:
,这是因为它不是解析错误,它认为它是一个常量并尝试将其解析为字符串。并且放置一个普通的字符串是一个有效的语句。
That is a notice.
reveals it.
Code I used:
Output:
That's because it's not a parse error, it thinks of it as a constant and tried to parse it as a string. And placing a normal string is a valid statement.
您可以尝试
error_reporting(-1)
-1 是
error_reporting
可以采用并且始终会采用的最大值。You can try
error_reporting(-1)
-1 is the maximum value
error_reporting
can take and always will be.在您的 PHP 脚本中,尝试将 error_reporting 设置为 E_ALL 并查看是否收到通知。
查看文档:http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
In your PHP script try setting error_reporting to E_ALL and see if you get a notice..
Check out the documentation: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
我遇到了这个问题,并通过将 /etc/php.ini 编辑为 display_errors = On 来修复它
I had this problem and fixed it by editing /etc/php.ini to display_errors = On
在主目录中创建 .htaccess 文件并放置:
error_reporting
常量的确切值可以在官方文档中找到 http://php.net/manual/en/errorfunc.constants.php当然,您应该在服务器中启用 mod_rewrite 。
Create .htaccess file in your main directory and place:
Exact values of
error_reporting
constants could be found in the official documentation http://php.net/manual/en/errorfunc.constants.phpOf course you should have mod_rewrite enabled in your server.