note 109890 deleted from errorfunc.constants by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:35:10 +0000 |
| Subject: | note 109890 deleted from errorfunc.constants by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190307@lists.php.net to get a copy of this message | ||
Note Submitter: SelfEvidentTruths mail com
----
As an alternative to the examples provided by vladvarna and russthom, the following will display all
error types currently reported by error_reporting. While it's just a personal preference, I
find if/then constructs much more intuitive and easier to read than case/switch's.
(Side note: The contants themselves could also be used for the "if" comparison, of course,
instead of 1, 2, 4, etc... However, this way self-documents the value of each constant.)
<?php
//Just for example:
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'on');
function Show_Error_Types() {
$E_level = error_reporting();
$E_types = '';
$spc = '<br>'; // Spacing: '<br>', or PHP_EOL, or whatever...
if ( $E_level & 1 ) { $E_types .= 'E_ERROR' .$spc; }
if ( $E_level & 2 ) { $E_types .= 'E_WARNING' .$spc; }
if ( $E_level & 4 ) { $E_types .= 'E_PARSE' .$spc; }
if ( $E_level & 8 ) { $E_types .= 'E_NOTICE' .$spc; }
if ( $E_level & 16 ) { $E_types .= 'E_CORE_ERROR' .$spc; }
if ( $E_level & 32 ) { $E_types .= 'E_CORE_WARNING' .$spc; }
if ( $E_level & 64 ) { $E_types .= 'E_COMPILE_ERROR' .$spc; }
if ( $E_level & 128 ) { $E_types .= 'E_COMPILE_WARNING' .$spc; }
if ( $E_level & 256 ) { $E_types .= 'E_USER_ERROR' .$spc; }
if ( $E_level & 512 ) { $E_types .= 'E_USER_WARNING' .$spc; }
if ( $E_level & 1024 ) { $E_types .= 'E_USER_NOTICE' .$spc; }
if ( $E_level & 2048 ) { $E_types .= 'E_STRICT' .$spc; }
if ( $E_level & 4096 ) { $E_types .= 'E_RECOVERABLE_ERROR'.$spc; }
if ( $E_level & 8192 ) { $E_types .= 'E_DEPRECATED' .$spc; }
if ( $E_level & 16384 ) { $E_types .= 'E_USER_DEPRECATED' .$spc; }
echo $spc.'error_reporting() is set to: '.$E_level.$spc.$E_types;
}
Show_Error_Types();
?>