php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63158 Misleading Example of ErrorException::getSeverity()
Submitted: 2012-09-25 01:26 UTC Modified: 2016-05-19 20:47 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: xianrenb at gmail dot com Assigned: salathe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xianrenb at gmail dot com
New email:
PHP Version: OS:

 

 [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();
}
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-26 04:26 UTC] 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.
 [2013-01-19 15:10 UTC] googleguy@php.net
-Status: Open +Status: Not a bug
 [2013-01-19 15:10 UTC] googleguy@php.net
nab
 [2013-01-20 00:42 UTC] xianrenb at gmail dot com
Bug closed without a proper reason again?
 [2013-01-20 01:01 UTC] xianrenb at gmail dot com
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?
 [2015-01-16 19:59 UTC] salathe@php.net
-Status: Not a bug +Status: Assigned -Assigned To: +Assigned To: salathe
 [2015-01-16 19:59 UTC] salathe@php.net
Assigning to myself, to get this "severity" issue sorted out once and for all.
 [2016-05-19 20:47 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339185
Log: Tie together ErrorException severity and error constants (doc #63158)
 [2016-05-19 20:47 UTC] salathe@php.net
-Status: Assigned +Status: Closed
 [2016-05-19 20:47 UTC] salathe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 17:01:29 2024 UTC