I'm trying to write my own error-reporting function. As a template I'm using an example that contains this code snippet:
if (!(error_reporting() & $errorcode)) {
return;
}
But what does it exactly do? I can't understand for what the ampersand is between error_reporting()
& $errorcode
(errorcode
is a function-parameter). I tried to output error_reporting()
and I got this (seems like it was called multiple):
int(32767)
Unknown errortype: [8] Undefined variable: kj
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
I searched then at php.net and saw that 32767
is the error E_ALL
, but it says in the line below the error code is 8
, which is an E_NOTICE
-error?! I'm overwhelmed and I am unable to understand is. Does someone is able to explain this behaviour detailed?
Let's see what the PHP documentation tells us about error_reporting()
. http://php.net/manual/en/function.error-reporting.php
"The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optional level is not set, error_reporting() will just return the current error reporting level."
You can pass it different "levels", for example: E_ALL
. Which will display all the errors.
This block will return immediately if error reporting is explicitly disabled. You don't want your error reporting to get invoked when the code creating the error disabled error reporting.