views:

130

answers:

4

Hello, I'm trying to not log notice errors, which are being written to an error log file on my server. I've tried (at the top of my index.php):

ini_set('display_errors', 0);
error_reporting(E_ALL ^ E_NOTICE);

But I'm still getting PHP Notice errors in said error log file.

I'm on a shared hosting environment, so I can't edit my php.ini file.

phpinfo() tells me:

  • Version 5.2.12
  • error_reporting 6143
  • error_log error_log
  • safe_mode Off
A: 

you can change the error reporting level to something different

error_reporting(E_ERROR | E_WARNING | E_PARSE);

see http://www.php.net/manual/en/function.error-reporting.php for more information

z3cko
I tried that, too, including you variation - still getting logged. Is there a way in php.ini to make ini_set() and error_reporting() NOT work?
A: 

Try doing:

error_reporting(E_ALL & ~E_NOTICE);

The error_reporting() directive will always works (PHP_INI_ALL).

Are you sure you're not including any library that changes your error reporting level?


Do error_reporting(0); and then do this:

var_dump(error_reporting());

What is the output?

Alix Axel
I've searched the entire project for "error_reporting" and it only shows a hit in the index.php file, and that's the error_reporting I added. There's no occurrences of "set_error_handler", either.
@magenta: No `ini_set()` either?
Alix Axel
There are two other ini_sets, but they set sendmail_from
6135 = `E_RECOVERABLE_ERROR` + `E_USER_NOTICE` + `E_USER_WARNING` + `E_USER_ERROR` + `E_COMPILE_WARNING` + `E_COMPILE_ERROR` + `E_CORE_WARNING` + `E_CORE_ERROR` + `E_PARSE` + `E_WARNING` + `E_ERROR`. No `E_NOTICE` there.
Alix Axel
@magenta: Do you have any `trigger_error()` function calls? Also, do notices still appear if you set `error_reporting(0);`?
Alix Axel
No trigger_error and yep to error_reporting(0), it's like no matter what I do, it has no effect.
@magenta: Then I'm sorry but I can't think of anything else... Have you tried contacting your sysadmin / host provider?
Alix Axel
That's next! :) Thanks everyone for your input, I do appreciate it, hopefully my ISP will be able to shed some light on this tomorrow. I'm off to bed.
@magenta: In your question you mention "error_reporting 6143", that number says that you have all the constants above **plus** `E_NOTICE`. It might be a clue.
Alix Axel
+4  A: 

If you're on an Apache server, try setting the value in a .htaccess file. The general format is:

php_flag  log_errors on
php_value error_log  /path/to/error.log
php_value error_reporting integer

where integer is the value you get from running something like:

echo E_ALL & ~E_NOTICE; // prints 30711

More info here:

http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/

echo
This doesn't seem to work, either.
A: 

Are you getting Notice's or "USER" Notice's in your log?

To disable both use:

error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE);
Bob Fanger
Shows in the log as "PHP Notice"
I believe both are logged as "PHP Notice". You could search the phpcode for "trigger_error" or E_USER_NOTICE.
Bob Fanger