PHP命令行运行不显示错误

AgA*_*AgA 9 php

如果我在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
Run Code Online (Sandbox Code Playgroud)

![在此处输入图像说明] [1]

我经历过:如何在PHP中获取有用的错误消息?

geo*_*org 24

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

php -d display_errors=on  script.php
Run Code Online (Sandbox Code Playgroud)

或者只需编辑ini并打开标志.

  • @AgA:正如Mark解释的那样,php甚至没有运行您的代码。它遇到解析错误并停止。 (2认同)