note 110108 deleted from class.errorexception by googleguy

From: Date: Thu, 20 Sep 2012 02:04:46 +0000
Subject: note 110108 deleted from class.errorexception by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190897@lists.php.net to get a copy of this message
Note Submitter: xianrenb at gmail dot com ---- I believe the example in the manual page as at Sep 20 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.

« previous php.notes (#190897) next »