note 65824 added to function.error-reporting
| From: | Chris at osu1 dot php dot net | Date: | Mon, 08 May 2006 14:31:03 +0000 |
| Subject: | note 65824 added to function.error-reporting | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110869@lists.php.net to get a copy of this message | ||
@ the_bug_the_bug at hotmail dot com
I'd extract the E_ALL first, because using it can shorter the string.
<?php
function error2string($value)
{
$level_names = array(
E_ERROR => 'E_ERROR', E_WARNING => 'E_WARNING',
E_PARSE => 'E_PARSE', E_NOTICE => 'E_NOTICE',
E_CORE_ERROR => 'E_CORE_ERROR', E_CORE_WARNING => 'E_CORE_WARNING',
E_COMPILE_ERROR => 'E_COMPILE_ERROR', E_COMPILE_WARNING =>
'E_COMPILE_WARNING',
E_USER_ERROR => 'E_USER_ERROR', E_USER_WARNING => 'E_USER_WARNING',
E_USER_NOTICE => 'E_USER_NOTICE', E_ALL => 'E_ALL' );
if(defined(E_STRICT)) $errorlevels[E_STRICT]='E_STRICT';
$levels=array();
if($value&E_ALL)
{
$levels[]='E_ALL';
$value&=~E_ALL;
}
foreach($level_names as $level=>$name)
if($value&$level) $levels[]=$name;
return implode(' | ',$levels);
}
?>
And a little function for opposite conversion.
<?php
function string2error($string)
{
$levels=explode('|',$string);
foreach($levels as $level)
{
$level=trim($level);
if(defined($level)) $value|=(int)constant($level);
}
return $value;
}
?>
If you want to make sure string2error uses only E_* constants, then just replace defined($level)
with in_array($level,$level_names) (using the array from the example above). And if you plan to use
both functions, you may as well define $level_names as a global var for better performance ;)
----
Server IP: 66.163.161.117
Probable Submitter: 83.28.219.136
----
X-Spam-Status: No, hits=3.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
UPPERCASE_25_50 autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.error-reporting.php
Edit -- http://master.php.net/note/edit/65824
Del: integrated -- http://master.php.net/note/delete/65824/integrated
Del: useless -- http://master.php.net/note/delete/65824/useless
Del: bad code -- http://master.php.net/note/delete/65824/bad+code
Del: spam -- http://master.php.net/note/delete/65824/spam
Del: non-english -- http://master.php.net/note/delete/65824/non-english
Del: in docs -- http://master.php.net/note/delete/65824/in+docs
Del: other reasons-- http://master.php.net/note/delete/65824
Reject -- http://master.php.net/note/reject/65824
Search -- http://master.php.net/manage/user-notes.php