Doc #63157 [Com]: Wrong Documentation of Class ErrorException
| From: | xianrenb at gmail dot com | Date: | Wed, 26 Sep 2012 02:42:46 +0000 |
| Subject: | Doc #63157 [Com]: Wrong Documentation of Class ErrorException | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8906@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63157&edit=1
ID: 63157
Comment by: xianrenb at gmail dot com
Reported by: xianrenb at gmail dot com
Summary: Wrong Documentation of Class ErrorException
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-09-25 01:04:56] xianrenb at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/class.errorexception
---
I think doc bug #63125 (https://bugs.php.net/bug.php?id=63125) was
closed as "Not a bug" without proper reasons, so I have to open a new
bug.
Please see the comments I made in the above bug report.
I think the documentation should match the source code, as in
https://github.com/php/php-src/blob/master/Zend/zend_exceptions.c
(24
Sep, 2012),
lines 221~228:
/* {{{ 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:
----------------
Class synopsis documented as:
ErrorException extends Exception {
/* Properties */
protected int $severity ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, int
$severity = E_ERROR [, string $filename = __FILE__ [, int $lineno =
__LINE__ [, Exception $previous = NULL ]]]]]] )
final public int getSeverity ( void )
/* Inherited methods */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}
Example documented as:
<?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();
?>
Actual result:
--------------
Class synopsis documented as:
ErrorException extends Exception {
/* Properties */
protected int $severity ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, int
$severity = 1 [, string $filename = __FILE__ [, int $lineno = __LINE__
[, Exception $previous = NULL ]]]]]] )
final public int getSeverity ( void )
/* Inherited methods */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}
Example documented as:
<?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();
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63157&edit=1