29

If I run this program on Centos as "php file.php" it shows no output but php -l shows it has errors(; after EOT missing). How do I enable error reporting in this case?

<?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

I've gone through: How can I get useful error messages in PHP?

Salman Zafar
  • 3,844
  • 5
  • 20
  • 43
AgA
  • 2,078
  • 7
  • 33
  • 62
  • 2
    If a script has syntax errors, then it cannot be executed; so setting display_errors is meaningless as it can't be executed... you should actually get a parse error displayed when trying to run it – Mark Baker Jun 11 '14 at 09:59
  • And your error is a missing `;` after the closing `EOT` – Mark Baker Jun 11 '14 at 10:01

3 Answers3

76

To override display_errors=Off in php.ini, add a -d flag to the command line:

php -d display_errors=on  script.php

Or just edit the ini and turn the flag on.

georg
  • 211,518
  • 52
  • 313
  • 390
  • Yes now it shows but haven't I already added in the PHP code? I've also tried ini_set('display_errors','On'); in the code. – AgA Jun 11 '14 at 10:05
  • 3
    @AgA: As Mark explained, php doesn't even run your code. It encounters a parse error and stops. – georg Jun 11 '14 at 10:06
  • So you mean -d display_errors=on should be used when running on command line? – AgA Jun 11 '14 at 10:16
  • @AgA: I'd simply edit the ini file, but if you can't, then yes, adding `-d` is the only option. – georg Jun 11 '14 at 10:19
3

Try to set error_reporting to E_ALL instead of -1, this did the trick for me.

source: http://www.php.net/manual/en/function.error-reporting.php#85096

Asko
  • 306
  • 2
  • 7
0

Execute:

php -i | grep "Loaded Configuration File"

And set display_startup_errors and display_errors in this file.

Marek
  • 7,337
  • 1
  • 22
  • 33