RE: [PHP-DEV] inheritance check too strict?
| From: | Jonathan Bond-Caron | Date: | Fri, 20 Aug 2010 13:10:08 +0000 |
| Subject: | RE: [PHP-DEV] inheritance check too strict? | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49478@lists.php.net to get a copy of this message | ||
On Fri Aug 20 08:24 AM, Nathan Rixham wrote:
> Jonathan Bond-Caron wrote:
> > On Fri Aug 20 06:54 AM, Jean-Sébastien H. wrote:
> >> 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 );
> >
> > ?>
>
> perhaps you mean..
>
> $t = new Child2;
> $t->dot( new P2 );
> $t->dot( new Child2 );
>
Oops, thanks :)
Maybe Stas can comment but I can't reproduce the E_STRICT warning
Is this php HEAD?
class ObjParent {
function set($param2 = '') {}
}
class ObjChild extends ObjParent {
function set(){ echo "."; }
}
$o = new ObjChild;
$o->set(); // runtime E_STRICT warning?