Re: inheritance check too strict?
| From: | Nathan Rixham | Date: | Fri, 20 Aug 2010 12:24:52 +0000 |
| Subject: | Re: inheritance check too strict? | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49476@lists.php.net to get a copy of this message | ||
Jonathan Bond-Caron wrote:
On Fri Aug 20 06:54 AM, Jean-Sébastien H. wrote:perhaps you mean.. $t = new Child2; $t->dot( new P2 ); $t->dot( new Child2 ); :)No it's wrong. A Child is a Parent so we must be able to pass a Parent to the method equals() defined on Child. The declaration of the parent functions must always be valid in the children.Maybe my OO theory is wrong but I was under the impression that the only way to enforce a signature is using an abstract class or interface? php allows it:PHP 5.2.13 with Suhosin-Patch 0.9.7 (cli) (built: Aug 14 2010 16:39:00) PHP 5.3.99-dev (cli) (built: Aug 20 2010 07:45:44)<?php class P { function dot(Child $o) { echo "."; } } class Child extends P { function dot(P $o) { echo "."; } } $t = new Child; $t->dot( new P ); $t->dot( new Child ); class P2 { function dot (P2 $o) { echo "."; } } class Child2 extends P2 { function dot(Child $o) { echo "."; } } $t = new Child; $t->dot( new P ); $t->dot( new Child ); ?>