31

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?

2
  • 3
    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 Commented Jun 11, 2014 at 9:59
  • And your error is a missing ; after the closing EOT Commented Jun 11, 2014 at 10:01

3 Answers 3

83

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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: As Mark explained, php doesn't even run your code. It encounters a parse error and stops.
So you mean -d display_errors=on should be used when running on command line?
@AgA: I'd simply edit the ini file, but if you can't, then yes, adding -d is the only option.
Ttaht option "-d display_errors=on" Does not work for me!
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

Comments

0

Execute:

php -i | grep "Loaded Configuration File"

And set display_startup_errors and display_errors in this file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.