note 59192 added to ref.errorfunc
| From: | tracerdx at tracerdx dot com | Date: | Tue, 29 Nov 2005 05:46:51 +0000 |
| Subject: | note 59192 added to ref.errorfunc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99276@lists.php.net to get a copy of this message | ||
I keep seeing qualification lists for error types/error-nums as arrays; In user notes and in the
manual itself. For example, in this manual entry's example, when trying to seperate behavior
for the variable trace in the error report:
<?php //...
// set of errors for which a var trace will be saved
$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
//and later...
if (in_array($errno, $user_errors)) {
//...whatever
}
//... ?>
I was under the impression that PHP error code values where bitwise flag values. Wouldn't
bitwise masking be better? So I propose a slightly better way:
<?php //...
$user_errors = E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE;
//...blah...
if ($errno & $user_errors) {
//...whatever
}
//... ?>
Or for those of you who don't like the idea of using an integer as the condition in an if
statement:
<?php
if (($errno & $user_errors) > 0) {
//...whatever
}
?>
I think that's much more efficient than using _yet another_ array() constuct and an in_array().
If I am wrong, and the E_* constants aren't supposed to be used in this fashion (ie, the
constans aren't guaranteed to be bitwise, which would be odd since that's how they're
setup in the php.ini file), then delete me. I just don't see why one should be using arrays
when bitwise comparisons will work, considering the bitwise method should be MUCH more efficient.
----
Manual Page -- http://www.php.net/manual/en/ref.errorfunc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59192
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59192&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59192&report=yes
Search -- http://master.php.net/manage/user-notes.php