PHP命令行运行不显示错误


PHP command line run does not show errors

如果我在Centos上运行这个程序为"php file.php",它显示没有输出,但php -l显示它有错误(;EOT丢失后)。在这种情况下,我如何启用错误报告?

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
$str = $_POST['name'];
file_put_contents("out.txt",$str);
print  <<<EOT
<html><body><h1>You've entered $str</h1></body></html>
EOT

我已经看过了:如何在PHP中获得有用的错误信息?

要覆盖php.ini中的display_errors=Off,在命令行中添加-d标志:

php -d display_errors=on  script.php

尝试将error_reporting设置为E_ALL而不是-1,这对我来说很有效。

85096年

来源:http://www.php.net/manual/en/function.error-reporting.php

Execute:

php -i | grep "Loaded Configuration File"

并在此文件中设置display_startup_errors和display_errors