Bug #66079 [NEW]: Exception constructor might ignore default arguments when overriden

From: Date: Mon, 11 Nov 2013 21:55:40 +0000
Subject: Bug #66079 [NEW]: Exception constructor might ignore default arguments when overriden
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182711@lists.php.net to get a copy of this message
From: cmbecker69 at gmx dot de Operating system: irrelevant PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Bug Bug description:Exception constructor might ignore default arguments when overriden 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 bug report at https://bugs.php.net/bug.php?id=66079&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66079&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66079&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66079&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66079&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66079&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66079&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66079&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66079&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66079&r=support Expected behavior: https://bugs.php.net/fix.php?id=66079&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66079&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66079&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66079&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66079&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66079&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66079&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66079&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66079&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66079&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66079&r=mysqlcfg

« previous php.bugs (#182711) next »