Search code examples
phperror-handlingerror-reporting

php Error Reporting Clarificartion (exact method, syntax & location)


Have been researching php error code for an for a quite a while now and there appears to be a conflict: error_reporting() appears to be both a method and property. But how can this be? What am I missing?

I've seen references to multiple uses an applications:

1a) error_reporting(E_ALL);
1b)error_reporting(E_ERROR | E_WARNING | E_PARSE);
1c)error_reporting(0);

Okay, so can use integer for true or false(1,0), got it. Various types of errors or all types of errors (E_ALL [constants]), got it. All php method so far - got it.

2) But where do you put the code? I can't even tell in php.net Is in config.php? or is httpd.config? or is php.ini? .htaccess?

3) And what's this [ error_reporting = ~E_ALL] & error_reporting = 0 ] Is it now a property?

4) What Works for Sure:

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

This is great! you can add this code (or similar) to your script and override any default settings for that particular page... and equally clear is display_errors. Just stick it in php.ini (or .user.ini with display_errors=On|Off) -- works every time.

So QUESTION: Where do you put the error_reporting code? and is it a property as well as a method?

Just want to be clear for technical purposes. Thanks guys


Solution

  • These are two separate things.

    There is a configuration property called error_reporting that you define in your php.ini file. This will be the default value.

    There is also a function called error_reporting() that you can use in your application to override the default value from php.ini.