为什么即使使用error_reporting(0), PHP也会响应错误?

时间:2021-02-23 22:01:50

What are some reasons why php would force errors to show, no matter what you tell it to disable?

为什么php会强制显示错误,不管您告诉它要禁用什么?

I have tried

我有试过

error_reporting(0);
ini_set('display_errors',0); 

with no luck.

没有运气。

8 个解决方案

#1


15  

Note the caveat in the manual at http://uk.php.net/error_reporting:

注意手册中的注意事项,请参阅http://uk.php.net/error_reporting:

Most of E_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E_STRICT errors (and vice versa).

大多数E_STRICT错误在编译时进行评估,因此这些错误不会在文件中报告,其中error_reporting增强为包含E_STRICT错误(反之亦然)。

If your underlying system is configured to report E_STRICT errors, these may be output before your code is even considered. Don't forget, error_reporting/ini_set are runtime evaluations, and anything performed in a "before-run" phase will not see their effects.

如果您的底层系统被配置为报告E_STRICT错误,那么这些错误可能会在考虑代码之前被输出。不要忘记,error_reporting/ini_set是运行时评估,在“运行前”阶段执行的任何操作都不会看到它们的效果。


Based on your comment that your error is...

根据你的评论,你的错误是……

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/REDACTED/public_html/dev.php on line 11

语法错误:语法错误,意外的T_VARIABLE, expect ',' or '; in /usr/home/ redacted/public_html /dev。php在第11行

Then the same general concept applies. Your code is never run, as it is syntactically invalid (you forgot a ';'). Therefore, your change of error reporting is never encountered.

同样的一般概念也适用。您的代码永远不会运行,因为它在语法上是无效的(您忘记了a ';')。因此,永远不会遇到错误报告的更改。

Fixing this requires a change of the system level error reporting. For example, on Apache you may be able to place...

解决这一问题需要更改系统级别的错误报告。例如,在Apache上,您可以放置…

php_value error_reporting 0

php_value error_reporting 0

in a .htaccess file to suppress them all, but this is system configuration dependent.

在.htaccess文件中禁止所有这些,但这是依赖于系统配置的。

Pragmatically, don't write files with syntax errors :)

实际上,不要写带有语法错误的文件:

#2


3  

To prevent errors from displaying you can

为了防止显示错误,您可以

  • Write in a .htaccess: php_flag display_errors 0
  • 写入.htaccess: php_flag display_errors 0。
  • Split your code in separate modules where the main (parent) php-file only sets the error_logging and then include() the other files.
  • 将代码分割到不同的模块中,其中主(父)php文件只设置error_logging,然后包含()其他文件。

#3


1  

use phpinfo to find the loaded php.ini and edit it to hide errors. it overrides what you put in your script.

使用phpinfo查找已加载的php。ini并编辑它以隐藏错误。它覆盖了脚本中的内容。

#4


1  

Is set_error_handler() used anywhere in your script? This overrides the error_reporting(0)

set_error_handler()是否在脚本中使用?这将覆盖error_reporting(0)

#5


0  

Use log_errors for them to be logged instead of displayed

使用log_errors记录它们而不是显示它们

#6


0  

If the setting is specified in Apache using php_admin_value it can't be changed in .htaccess or in runtime. See: http://docs.php.net/configuration.changes

如果使用php_admin_value在Apache中指定设置,则不能在.htaccess中或运行时中更改设置。参见:http://docs.php.net/configuration.changes

#7


0  

Pragmatically, don't write files with syntax errors :)

实际上,不要写带有语法错误的文件:

To ensure there's no syntax errors in your file, run the following:

要确保文件中没有语法错误,请运行以下命令:

php -l YOUR_FILE_HERE.php

This will output something like this:

这将输出如下内容:

PHP Parse error:  syntax error, unexpected '}' in Connection.class.php on line 31

Hope this helps.

希望这个有帮助。

#8


0  

Just add below code in your index.php file:

只需在索引中添加以下代码。php文件:

ini_set('display_errors', False);

报错(display_errors,假);

#1


15  

Note the caveat in the manual at http://uk.php.net/error_reporting:

注意手册中的注意事项,请参阅http://uk.php.net/error_reporting:

Most of E_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E_STRICT errors (and vice versa).

大多数E_STRICT错误在编译时进行评估,因此这些错误不会在文件中报告,其中error_reporting增强为包含E_STRICT错误(反之亦然)。

If your underlying system is configured to report E_STRICT errors, these may be output before your code is even considered. Don't forget, error_reporting/ini_set are runtime evaluations, and anything performed in a "before-run" phase will not see their effects.

如果您的底层系统被配置为报告E_STRICT错误,那么这些错误可能会在考虑代码之前被输出。不要忘记,error_reporting/ini_set是运行时评估,在“运行前”阶段执行的任何操作都不会看到它们的效果。


Based on your comment that your error is...

根据你的评论,你的错误是……

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/REDACTED/public_html/dev.php on line 11

语法错误:语法错误,意外的T_VARIABLE, expect ',' or '; in /usr/home/ redacted/public_html /dev。php在第11行

Then the same general concept applies. Your code is never run, as it is syntactically invalid (you forgot a ';'). Therefore, your change of error reporting is never encountered.

同样的一般概念也适用。您的代码永远不会运行,因为它在语法上是无效的(您忘记了a ';')。因此,永远不会遇到错误报告的更改。

Fixing this requires a change of the system level error reporting. For example, on Apache you may be able to place...

解决这一问题需要更改系统级别的错误报告。例如,在Apache上,您可以放置…

php_value error_reporting 0

php_value error_reporting 0

in a .htaccess file to suppress them all, but this is system configuration dependent.

在.htaccess文件中禁止所有这些,但这是依赖于系统配置的。

Pragmatically, don't write files with syntax errors :)

实际上,不要写带有语法错误的文件:

#2


3  

To prevent errors from displaying you can

为了防止显示错误,您可以

  • Write in a .htaccess: php_flag display_errors 0
  • 写入.htaccess: php_flag display_errors 0。
  • Split your code in separate modules where the main (parent) php-file only sets the error_logging and then include() the other files.
  • 将代码分割到不同的模块中,其中主(父)php文件只设置error_logging,然后包含()其他文件。

#3


1  

use phpinfo to find the loaded php.ini and edit it to hide errors. it overrides what you put in your script.

使用phpinfo查找已加载的php。ini并编辑它以隐藏错误。它覆盖了脚本中的内容。

#4


1  

Is set_error_handler() used anywhere in your script? This overrides the error_reporting(0)

set_error_handler()是否在脚本中使用?这将覆盖error_reporting(0)

#5


0  

Use log_errors for them to be logged instead of displayed

使用log_errors记录它们而不是显示它们

#6


0  

If the setting is specified in Apache using php_admin_value it can't be changed in .htaccess or in runtime. See: http://docs.php.net/configuration.changes

如果使用php_admin_value在Apache中指定设置,则不能在.htaccess中或运行时中更改设置。参见:http://docs.php.net/configuration.changes

#7


0  

Pragmatically, don't write files with syntax errors :)

实际上,不要写带有语法错误的文件:

To ensure there's no syntax errors in your file, run the following:

要确保文件中没有语法错误,请运行以下命令:

php -l YOUR_FILE_HERE.php

This will output something like this:

这将输出如下内容:

PHP Parse error:  syntax error, unexpected '}' in Connection.class.php on line 31

Hope this helps.

希望这个有帮助。

#8


0  

Just add below code in your index.php file:

只需在索引中添加以下代码。php文件:

ini_set('display_errors', False);

报错(display_errors,假);