6

I'm running ubuntu 10.04 + nginx + php-fpm 5.4

If I set display_errors = On in php.ini all errors are printed. If Instead I set that to off and then use ini_set('display_errors, '1'); directly in the script they will show as well but not the parse errors, just a blank page. I tried to play with error_reporting too and E_STRICT but I couldn't find a way!

5 Answers 5

21

If you disable display_errors in php.ini, and later enable it in your PHP script using ini_set(), it will only be enabled after the line containing that ini_set() call has been executed.

Parse errors occur before the PHP script even starts -- when the PHP file is parsed (hence the "parse error" name).

Which means they occur before your ini_set() has even a chance of being executed -- which means that, in your case, display_errors is not enabled when the parse error occurs ; and, as a consequence, you don't get anything displayed.

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

3 Comments

so they only solution to show parse errors is to enable it in the ini file?
it seems pretty logical -- and kind of fits with the second note on php.net/manual/en/… (which says "fatal", but the idea is there)
yes, i have added ( un commented ) the following lines, and the parse errors are being displayed now. error_reporting Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED Development Value: E_ALL Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
13

here I am years after this was answered, but I found a way around this.

For the script I'm writing, I created a second script which includes the ini_set() directives, followed by an include for the script I really am working on.

To with, here is test_run.php

<?php

ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL);

include('./my_script.php');

?>

4 Comments

+1 for this; getting this issue with apache+php7, even though I had .htaccess set with php_flag display_errors on, it seems this one kicks in too late and I was not getting the errors reported. Of course I don't want to enable this site-wide, but just to that directory, and this workaround allowed me to "wrap" a debug version of the script that way.
This is actually super helpful, you deserve a lot more points than you got here!
you saved my day!
I have no idea how has it come to happen that I never seen this until now. It saves time. I know is not proper debugging, but it saves time.
3

Aside from turning on display_errors, you can also watch error logs. Typically, running Ubuntu + apache, your error log is going to be in /var/log/apache2/error_log. To watch in real time what's happening, you run something like tail -f /var/log/apache2/error_log.

This can sometimes be more straightforward than fussing with php settings.

1 Comment

The question asks about nginx, not apache.
0

**You must enable error displaying in the php.ini file **

I have added ( un-commented ) the following lines, and the parse errors are being displayed now.

error_reporting 
Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED 
Development Value: E_ALL
Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

Comments

-1

Try error_reporting(E_ALL);. Or the docs

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.