Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between error_reporting() and ini_set('error_reporting')?

When using error_reporting() or ini_set('error_reporting') in my scripts, are there any functionality differences between the two? Is one method preferred over the other?

For what it's worth, I see many frameworks using error_reporting(), but both options appear to be set during runtime only, then reset back to their default in php.ini after script execution.

like image 966
Jeff Avatar asked Dec 23 '09 20:12

Jeff


People also ask

What is PHP error level?

A PHP error isn't a single thing, but comes in 4 different types: parse or syntax errors. fatal errors. warning errors. notice errors.

How do I display PHP error messages?

The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);


2 Answers

"Two roads leading you to Rome": ini_set('error_reporting', ) overrides the parameter set in the php.ini file. error_reporting() receives level number or level id

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

Both options take effect until the script ends its execution. The next one will use the params defined in the .ini, again.

like image 114
Alfabravo Avatar answered Sep 28 '22 11:09

Alfabravo


The only small functional difference seems to be that ini_set returns false when it was unable to change the setting and error_reporting always returns the old error level.

like image 30
Pekka Avatar answered Sep 28 '22 09:09

Pekka