Re: No inheritance check in constructor ?
| From: | Ralph Schindler | Date: | Fri, 28 Oct 2011 15:51:50 +0000 |
| Subject: | Re: No inheritance check in constructor ? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55984@lists.php.net to get a copy of this message | ||
Hi Jean-Sebastien,
I'd say this is a harder-to-grasp concept and leads to this common misconception.
Have a look here, particularly at my reply in the comments section:
http://devzone.zend.com/article/15273
In a nutshell, ctors (constructors) are not subject to LSP (liskov sub. principle) because a type does not yet exist; the type is the product of the ctor.
-ralph
On 10/28/11 10:33 AM, Jean-Sébastien H. wrote:
Ok it's a documented behaviour, I should read more carefully. http://php.net/manual/en/language.oop5.decon.php Unlike with other methods, PHP will not generate an E_STRICT level error message when __construct() is overridden with different parameters than the parent __construct() method has. But I think, it's a lack in PHP ? On Fri, 28 Oct 2011 17:22:53 +0200, Jean-Sébastien H. <jeanseb@au-fil-du.net> wrote:Hi, Is it an expected behaviour ? See attached test file. ---- EXPECTED OUTPUT Strict Standards: Declaration of ObjChild::method() should be compatible with that of ObjParent::method() in %s on line 15 Strict standards: Declaration of ObjChild::__construct() should be compatible with that of ObjParent::__construct() in %s on line 17 ---- ACTUAL OUTPUT Strict Standards: Declaration of ObjChild::method() should be compatible with that of ObjParent::method() in %s on line 15 ---- FAILED NB : The real actual output of the phpt is empty. Can we test strict error with run-tests ? Regards, -- Jean-Sébastien H. au-fil-du.net