note 109890 added to errorfunc.constants
| From: | SelfEvidentTruthsmailcom | Date: | Thu, 30 Aug 2012 23:33:07 +0000 |
| Subject: | note 109890 added to errorfunc.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190286@lists.php.net to get a copy of this message | ||
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();
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.99.64.218
----
Manual Page -- http://www.php.net/manual/en/errorfunc.constants.php
Edit -- https://master.php.net/note/edit/109890
Del: integrated -- https://master.php.net/note/delete/109890/integrated
Del: useless -- https://master.php.net/note/delete/109890/useless
Del: bad code -- https://master.php.net/note/delete/109890/bad+code
Del: spam -- https://master.php.net/note/delete/109890/spam
Del: non-english -- https://master.php.net/note/delete/109890/non-english
Del: in docs -- https://master.php.net/note/delete/109890/in+docs
Del: other reasons-- https://master.php.net/note/delete/109890
Reject -- https://master.php.net/note/reject/109890
Search -- https://master.php.net/manage/user-notes.php