Doc #63158 [Com]: Misleading Example of ErrorException::getSeverity()

From: Date: Sun, 20 Jan 2013 00:42:40 +0000
Subject: Doc #63158 [Com]: Misleading Example of ErrorException::getSeverity()
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9451@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63158&edit=1 ID: 63158 Comment by: xianrenb at gmail dot com Reported by: xianrenb at gmail dot com Summary: Misleading Example of ErrorException::getSeverity() Status: Not a bug Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Bug closed without a proper reason again? Previous Comments: ------------------------------------------------------------------------ [2013-01-19 15:10:51] googleguy@php.net nab ------------------------------------------------------------------------ [2012-09-26 04:26:17] xianrenb at gmail dot com One may believe an instance of class ErrorException with $severity being 20 is more severe than another instance with $severity being 10, and argue that $severity of class ErrorException has nothing to do with those error level constants, but I think this happens just because the class is documented in a way that is not matching the source code. Please consider the case of using set_error_handler() without using class ErrorException. How could one determine the severity of an error? The only solution is to compare the $errno with error level constants, i.e. E_* values. These error level constants are built-in constants provided by the PHP system. If one wants to use his own system of determining the severity of an error, he has to define those constants somewhere. It is very clear that those are custom things, and it is very strange to do so. ErrorException is not a custom class. Anything dealing with it should use what the PHP system provides. In other words, it only makes sense to use $severity of class ErrorException by comparing it with error level constants provided by the PHP system. And the source code says the default value of $severity is E_ERROR. It should be noted that larger value of $severity does not mean the error is more severe. The same thinking should apply to error level constants. However, $severity should represent the severity level of an error, which could be determined by comparing $severity with error level constants. ------------------------------------------------------------------------ [2012-09-25 01:26:14] xianrenb at gmail dot com Description: ------------ --- From manual page: http://www.php.net/errorexception.getseverity#refsect1- errorexception.getseverity-examples --- According to https://github.com/php/php-src/blob/master/Zend/zend_exceptions.c (Sep 24, 2012), lines 221~258 and 327~335 (especially 221~228), the method getSeverity() should return error level constants as described in http://hk.php.net/manual/en/errorfunc.constants.php , as the default value of $severity is exactly E_ERROR: /* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Exception previous]]]) ErrorException constructor */ ZEND_METHOD(error_exception, __construct) { char *message = NULL, *filename = NULL; long code = 0, severity = E_ERROR, lineno; zval *object, *previous = NULL; int argc = ZEND_NUM_ARGS(), message_len, filename_len; Expected result: ---------------- <?php try { throw new ErrorException("Exception message", 0, E_USER_NOTICE); } catch(ErrorException $e) { echo "This exception severity is: " . $e->getSeverity(); } ?> Actual result: -------------- <?php try { throw new ErrorException("Exception message", 0, 75); } catch(ErrorException $e) { echo "This exception severity is: " . $e->getSeverity(); } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63158&edit=1

« previous php.doc.bugs (#9451) next »