note 88065 added to function.error-reporting

From: Date: Thu, 08 Jan 2009 13:58:17 +0000
Subject: note 88065 added to function.error-reporting
Groups: php.notes 
Request: Send a blank email to php-notes+get-148945@lists.php.net to get a copy of this message
To Chris, string2error() function is not working if you have input such as 'E_ALL ^ E_NOTICE'. Below is an updated version that accept any string input (either in the form of 'E_ALL ^ E_NOTICE' or also in the form of 'E_ALL | ~E_NOTICE'). It takes as input your error level string and return it's corresponding integer: <?php function string2error($error_level) { if (!$error_level) { throw new Exception(__FUNCTION__. ': Input must be a non empty string'); } // standardize format of input string $error_level = str_replace(array('^', '&'), array('&~', '|'), $error_level); // parse input string $error_value = 0; $parts = explode('|', $error_level); foreach ($parts as $level) { $level = trim($level); if ($removed_level = $level[0] === '~') { $level = ltrim($level, '~ '); $value ^= (int)constant($level); } else { $value |= (int)constant($level); } } return $value; } print eval("return E_ALL ^ E_NOTICE;"); # print 6135 print string2error('E_ALL ^ E_NOTICE'); # print 6135 ?> ---- Server IP: 130.206.1.5 Probable Submitter: 84.123.119.214 ---- Manual Page -- http://www.php.net/manual/en/function.error-reporting.php Edit -- https://master.php.net/note/edit/88065 Del: integrated -- https://master.php.net/note/delete/88065/integrated Del: useless -- https://master.php.net/note/delete/88065/useless Del: bad code -- https://master.php.net/note/delete/88065/bad+code Del: spam -- https://master.php.net/note/delete/88065/spam Del: non-english -- https://master.php.net/note/delete/88065/non-english Del: in docs -- https://master.php.net/note/delete/88065/in+docs Del: other reasons-- https://master.php.net/note/delete/88065 Reject -- https://master.php.net/note/reject/88065 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148945) next »