note 88065 deleted from function.error-reporting by danbrown

From: Date: Mon, 19 Jan 2009 17:01:39 +0000
Subject: note 88065 deleted from function.error-reporting by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149464@lists.php.net to get a copy of this message
Note Submitter: remy dot damour at -please-no-spam-laposte dot net ---- 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 ?>

« previous php.notes (#149464) next »