note 110108 added to class.errorexception

From: Date: Thu, 20 Sep 2012 01:10:13 +0000
Subject: note 110108 added to class.errorexception
Groups: php.notes 
Request: Send a blank email to php-notes+get-190896@lists.php.net to get a copy of this message
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. ---- Server IP: 180.92.182.149 Probable Submitter: 124.244.171.10 ---- Manual Page -- http://www.php.net/manual/en/class.errorexception.php Edit -- https://master.php.net/note/edit/110108 Del: integrated -- https://master.php.net/note/delete/110108/integrated Del: useless -- https://master.php.net/note/delete/110108/useless Del: bad code -- https://master.php.net/note/delete/110108/bad+code Del: spam -- https://master.php.net/note/delete/110108/spam Del: non-english -- https://master.php.net/note/delete/110108/non-english Del: in docs -- https://master.php.net/note/delete/110108/in+docs Del: other reasons-- https://master.php.net/note/delete/110108 Reject -- https://master.php.net/note/reject/110108 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190896) next »