Bug->Doc #66079 [Asn]: Exception constructor might ignore default arguments when overriden
| From: | cmb@php.net | Date: | Thu, 29 Sep 2016 10:34:08 +0000 |
| Subject: | Bug->Doc #66079 [Asn]: Exception constructor might ignore default arguments when overriden | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13963@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66079&edit=1
ID: 66079
Updated by: cmb@php.net
Reported by: cmbecker69 at gmx dot de
Summary: Exception constructor might ignore default arguments
when overriden
Status: Assigned
-Type: Bug
+Type: Documentation Problem
Package: Scripting Engine problem
Operating System: irrelevant
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
We can't easily change the current behavior for BC reasons, so I'm
switching to doc bug.
Previous Comments:
------------------------------------------------------------------------
[2013-11-11 21:55:39] cmbecker69 at gmx dot de
Description:
------------
When overriden, calling the constructor of class Exception
ignores the default arguments, if the properties $code and
$message are already set.
From looking at the implementation of the constructor[1],
the behavior is to be expected, because when the default
values are passed for $code and $message, zend_update_property_*()
is not called.
I am fully aware that the given test script shows a bad
programming practise, but it would work for user defined
classes, and the unusual behavior of the Exception constructor
doesn't seem to be documented. At least this should be done, IMHO.
[1] <http://lxr.php.net/xref/PHP_5_5/Zend/zend_exceptions.c#223>
Test script:
---------------
// cf. <http://3v4l.org/3Ylvi#v430>
class MyException extends Exception
{
function __construct()
{
$this->code = 42;
$this->message = "foo";
parent::__construct();
}
}
try {
throw new MyException();
} catch (MyException $e) {
var_dump($e->getCode());
var_dump($e->getMessage());
}
Expected result:
----------------
int(0)
string(0) ""
Actual result:
--------------
int(42)
string(3) "foo"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66079&edit=1