11

What are some reasons why PHP would force errors to show, no matter what you tell it to disable?

I have tried

error_reporting(0);
ini_set('display_errors', 0); 

with no luck.

3
  • I don't know this answer, but if possible it may help if you provide an example of an error that was displayed with reporting turned off. Commented Sep 16, 2008 at 23:23
  • Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/johnq/public_html/dev.php on line 11 the only PHP in dev.php is this: <?php error_reporting(0); echo "test" $test = "123"; ?> Commented Sep 16, 2008 at 23:28
  • Without that error message, it might have taken you a lot longer to realize that your script wasn't running simply because of a missing semicolon. Commented Jan 2, 2011 at 15:59

8 Answers 8

15

Note the caveat in the manual at http://uk.php.net/error_reporting:

Most of E_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E_STRICT errors (and vice versa).

If your underlying system is configured to report E_STRICT errors, these may be output before your code is even considered. Don't forget, error_reporting/ini_set are runtime evaluations, and anything performed in a "before-run" phase will not see their effects.


Based on your comment that your error is...

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/REDACTED/public_html/dev.php on line 11

Then the same general concept applies. Your code is never run, as it is syntactically invalid (you forgot a ';'). Therefore, your change of error reporting is never encountered.

Fixing this requires a change of the system level error reporting. For example, on Apache you may be able to place...

php_value error_reporting 0

in a .htaccess file to suppress them all, but this is system configuration dependent.

Pragmatically, don't write files with syntax errors :)

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

Comments

3

To prevent errors from displaying you can

  • Write in a .htaccess: php_flag display_errors 0
  • Split your code in separate modules where the main (parent) PHP file only sets the error_logging and then include() the other files.

Comments

1

Use phpinfo to find the loaded php.ini and edit it to hide errors. It overrides what you put in your script.

Comments

1

Is set_error_handler() used anywhere in your script? This overrides error_reporting(0).

Comments

0

Pragmatically, don't write files with syntax errors :)

To ensure there's no syntax errors in your file, run the following:

php -l YOUR_FILE_HERE.php

This will output something like this:

PHP Parse error:  syntax error, unexpected '}' in Connection.class.php on line 31

Comments

0

Just add the below code in your index.php file:

ini_set('display_errors', False);

Comments

0

Use log_errors for them to be logged instead of displayed.

1 Comment

<?php ini_set('error_log','/error_log'); ini_set('log_errors',TRUE); echo "test" $test = "123"; ?> Still causes the same error, unfortunately. I'm looking for a way to do this without modifying php.ini. Is that possible?
0

If the setting is specified in Apache using php_admin_value, it can't be changed in .htaccess or at runtime.

See: How to change configuration settings

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.