note 110116 added to class.errorexception
| From: | xianrenbatgmaildotcom | Date: | Fri, 21 Sep 2012 05:12:30 +0000 |
| Subject: | note 110116 added to class.errorexception | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190942@lists.php.net to get a copy of this message | ||
I believe the example in the manual page as at Sep 21 is wrong:
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
/* Trigger exception */
strpos();
?>
The correct one should be:
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
/* Trigger exception */
strpos();
?>
Reasons:
1. According to the manual page of set_error_handler(), $errno contains
the level of the error raised, as an integer. This is the same meaning
as $severity of class ErrorException.
2. Class ErrorException has property $severity, but class Exception does
not have the same property. It only makes sense if $severity is set to
something useful (non-zero), and related to error.
3. $severity has a default value of 1, which is the same value as
E_ERROR, while $code has a default value of 0.
4. Most notes contributed by other PHP users, if not all, use
ErrorException in the same way as the correct version that I
suggested above.
----
Server IP: 69.147.83.199
Probable Submitter: 124.244.171.10
----
Manual Page -- http://www.php.net/manual/en/class.errorexception.php
Edit -- https://master.php.net/note/edit/110116
Del: integrated -- https://master.php.net/note/delete/110116/integrated
Del: useless -- https://master.php.net/note/delete/110116/useless
Del: bad code -- https://master.php.net/note/delete/110116/bad+code
Del: spam -- https://master.php.net/note/delete/110116/spam
Del: non-english -- https://master.php.net/note/delete/110116/non-english
Del: in docs -- https://master.php.net/note/delete/110116/in+docs
Del: other reasons-- https://master.php.net/note/delete/110116
Reject -- https://master.php.net/note/reject/110116
Search -- https://master.php.net/manage/user-notes.php