5.6.3版本中的phperror_reporting()方法

php error_reporting() method in the 5.6.3 version

在下面的例子中:

<?php
 // this code is written to test error reporting function in runtime
error_reporting(0);
echo $var = 'hex'  // I have made this mistake here by my will but error reporting message still pops up.
$name = 'rex';
?>

我想在运行时关闭 php 中的错误报告。我使用了语句 error_reporting(0); 但它不适用于我的版本,它尝试了以下问题 php error reporint 提出的解决方案,但它不起作用。我认为这里使用了另一个版本。 我的 php 版本是 php 5.6.3。我已经检查了 php doumentation 的解决方案,但找不到答案。 我该如何解决这个问题?

你有一个编译错误; error_reporting 上的注释表明编译时错误可能无法通过 运行 时间指令进行控制。

这不会导致出现任何错误

error_reporting(0);
echo $var = 'hex';
$name = 'rex';
echo $A;

这会导致出现错误

error_reporting(E_ALL);
echo $var = 'hex';
$name = 'rex';
echo $A;

这也会导致出现错误

error_reporting(0);
echo $var = 'hex'
$name = 'rex';
echo $A;

第二行代码末尾少了一个分号

echo $var = 'hex' 

这是错误的原因,这是一个编译错误,而不是运行时错误。因为无法编译成功,脚本根本没有启动。没有运行时,脚本永远不会 运行.

无法抑制编译错误。它们的目的是向程序员表明脚本无法编译以及原因。