5.6.3版本中的php error_reporting()方法

时间:2015-01-16 12:02:54

标签: php error-reporting

在以下示例中:

<?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是否有解决方案,但我无法找到答案。 我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

你有编译错误;对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;

答案 1 :(得分:1)

第二行代码

末尾缺少分号
echo $var = 'hex' 

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

无法抑制编译错误。他们的目的是向程序员展示脚本无法编译以及原因。