不显示 PHP 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7667160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:08:08  来源:igfitidea点击:

Not displaying PHP errors

phpapacheapache2error-reporting

提问by beetree

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:

如果我运行以下代码(解析错误),我不会收到任何错误,但仍会显示文本“Hello world”:

<?php
echo "Hello world";
piwejfoiwjefoijwef
?>

If I place the parse error before the code it does however not display "Hello world":

如果我将解析错误放在代码之前,它不会显示“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

当我打印 phpinfo(在同一个文件,同一个目录中)时,我有以下设置: 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:

如果我还尝试在脚本中设置错误报告并使用以下代码运行它,我仍然没有收到任何错误或警告,但会显示文本“Hello world”:

<?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):

我的 php.ini 文件具有以下值(并且我已经重新启动了 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.

我正在使用 64 位 AWS EC2 在 Amazon AMI 上运行 Apache/PHP/MySQL。我对服务器配置不太了解。当我转换到亚马逊服务器时,错误就开始了。除了错误报告服务器和 Apache/PHP 运行完美。

Please guide me in what I can do to fix the problem.

请指导我如何解决问题。

Thanks!

谢谢!

回答by Madara's Ghost

That is a notice.

那是一个通知。

error_reporting(E_ALL);

reveals it.

揭示它。

Code I used:

我使用的代码:

<?php

    error_reporting(E_ALL); ini_set('display_errors', '1');
    echo "Hello world";
    owieufpowiejf

?>

Output:

输出:

Hello world

Notice: Use of undefined constant owieufpowiejf - assumed 'owieufpowiejf' in /code/14B4LY on line 5

你好,世界

注意:使用未定义的常量 owieufpowiejf - 在第 5 行的 /code/14B4LY 中假定为 'owieufpowiejf'

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.

那是因为它不是解析错误,而是将其视为常量并尝试将其解析为字符串。放置一个普通字符串是一个有效的语句。

回答by Ole

You can try error_reporting(-1)

你可以试试 error_reporting(-1)

-1 is the maximum value error_reportingcan take and always will be.

-1 是error_reporting可以取的最大值,并且永远都是。

回答by Krasimir

Create .htaccess file in your main directory and place:

在您的主目录中创建 .htaccess 文件并放置:

php_flag display_errors on 
# 7 stands for E_ERROR | E_WARNING | E_PARSE
php_value error_reporting 7

Exact values of error_reportingconstants could be found in the official documentation http://php.net/manual/en/errorfunc.constants.php

error_reporting可以在官方文档http://php.net/manual/en/errorfunc.constants.php 中找到常量的确切值

Of course you should have mod_rewrite enabled in your server.

当然,您应该在服务器中启用 mod_rewrite。

回答by Jake

In your PHP script try setting error_reporting to E_ALL and see if you get a notice..

在您的 PHP 脚本中,尝试将 error_reporting 设置为 E_ALL 并查看您是否收到通知。

error_reporting(E_ALL)

Check out the documentation: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

查看文档:http: //www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

回答by Tom Kincaid

I had this problem and fixed it by editing /etc/php.ini to display_errors = On

我遇到了这个问题并通过将 /etc/php.ini 编辑为 display_errors = On 来修复它

回答by mario

Calling error_reporting()in the same script that contains the syntax error is never going to work.

调用error_reporting()包含语法错误的同一个脚本永远不会起作用。

<?php
echo "Hello world";
piwejfoiwjefoijwef
?>

This script in particular does not get you any syntax error, because it does not contain any syntax error. It's just an echostatement and a bare constant in the second line. The trailing semicolon can be omitted right before the ?>

特别是这个脚本不会给你任何语法错误,因为它不包含任何语法错误。它只是echo第二行中的一个语句和一个裸露的常量。尾随分号可以省略?>

You would get a notice, if it hadn't been turned off. Again, you didn't enable E_NOTICEin your other test.

如果它没有被关闭,你会收到通知。同样,您没有E_NOTICE在其他测试中启用。