I was searching the manual for error_reporting
. There I found an example which lists all the error reporting levels in the browser window. I went through the code and some coding style seems unfamiliar to me and I couldn't understand what exactly it does.
In the manual, it says error_reporting ()
returns:
Returns the old
error_reporting level
or the current level if no level parameter is given
I know error_reporting(level)
determines what type of error to show or not to show. But what it returns when it is assigned to a variable ? like the following:
$errLvl = error_reporting();
I have printed $errLvl
and it returned 22527
. I don't understand what it means? Can any one explain it to me in plain English?
There is a function called FriendlyErrorType($type)
which will accept an error type and print it in the browser. But it is given a parameter ($errLvs & pow(2,i))
. What does &
operator supposed to do? I mean what is the function of &
operator in the argument?
print FriendlyErrorType($errLvl & pow(2, $i))
fullCode:
$errLvl = error_reporting();
echo $errLvl.'</br>';
for ($i = 0; $i < 15; $i++ ) {
print FriendlyErrorType($errLvl & pow(2, $i)) . "<br>\\n";
}
function FriendlyErrorType($type)
{
switch($type)
{
case E_ERROR: // 1 //
return 'E_ERROR';
case E_WARNING: // 2 //
return 'E_WARNING';
case E_PARSE: // 4 //
return 'E_PARSE';
case E_NOTICE: // 8 //
return 'E_NOTICE';
case E_CORE_ERROR: // 16 //
return 'E_CORE_ERROR';
case E_CORE_WARNING: // 32 //
return 'E_CORE_WARNING';
case E_COMPILE_ERROR: // 64 //
return 'E_COMPILE_ERROR';
case E_COMPILE_WARNING: // 128 //
return 'E_COMPILE_WARNING';
case E_USER_ERROR: // 256 //
return 'E_USER_ERROR';
case E_USER_WARNING: // 512 //
return 'E_USER_WARNING';
case E_USER_NOTICE: // 1024 //
return 'E_USER_NOTICE';
case E_STRICT: // 2048 //
return 'E_STRICT';
case E_RECOVERABLE_ERROR: // 4096 //
return 'E_RECOVERABLE_ERROR';
case E_DEPRECATED: // 8192 //
return 'E_DEPRECATED';
case E_USER_DEPRECATED: // 16384 //
return 'E_USER_DEPRECATED';
}
return "";