|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-09-25 01:26 UTC] 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(); } ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 04:00:01 2025 UTC |
75 = 64 + 8 + 2 + 1 Therefore, under common/practical usage, the current example <?php try { throw new ErrorException("Exception message", 0, 75); } catch(ErrorException $e) { echo "This exception severity is: " . $e->getSeverity(); } ?> is equivalent to <?php try { throw new ErrorException("Exception message", 0, E_CORE_ERROR | E_NOTICE | E_WARNING | E_ERROR); } catch(ErrorException $e) { echo "This exception severity is: " . $e->getSeverity(); } ?> Would anyone think it is possible or useful to do so?