Doc #63158 [Nab->Asn]: Misleading Example of ErrorException::getSeverity()
| From: | salathe@php.net | Date: | Fri, 16 Jan 2015 19:59:34 +0000 |
| Subject: | Doc #63158 [Nab->Asn]: Misleading Example of ErrorException::getSeverity() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11859@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
Updated by: salathe@php.net
Reported by: xianrenb at gmail dot com
Summary: Misleading Example of ErrorException::getSeverity()
-Status: Not a bug
+Status: Assigned
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: salathe
Block user comment: N
Private report: N
New Comment:
Assigning to myself, to get this "severity" issue sorted out once and for all.
Previous Comments:
------------------------------------------------------------------------
[2013-01-20 01:10:35] xianrenb at gmail dot com
Related To: Bug #63157
------------------------------------------------------------------------
[2013-01-20 01:01:27] 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?
------------------------------------------------------------------------
[2013-01-20 00:42:39] xianrenb at gmail dot com
Bug closed without a proper reason again?
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=63158
--
Edit this bug report at https://bugs.php.net/bug.php?id=63158&edit=1