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.
A PHP error isn't a single thing, but comes in 4 different types: parse or syntax errors. fatal errors. warning errors. notice errors.
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);
"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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With