RE: [PHP-DEV] RfC: rethink OO inheritance strictness
| From: | Daine Mamacos | Date: | Fri, 21 Jul 2006 10:36:33 +0000 |
| Subject: | RE: [PHP-DEV] RfC: rethink OO inheritance strictness | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-24817@lists.php.net to get a copy of this message | ||
If a constructor gets overridden, why should it not be the same behaviour
with all methods?
-----Original Message-----
From: Derick Rethans [mailto:derick@php.net]
Sent: 21 July 2006 10:31
To: Mike Bretz
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] RfC: rethink OO inheritance strictness
On Fri, 21 Jul 2006, Mike Bretz wrote:
> Michael Wallner wrote:
> > mike@honeybadger:~/build/php-unicode-debug$ cli
> > -d"error_reporting=8191" -r 'class c{function f(){}} class d extends
> > c{function f($a){}}'
> > Fatal error: Declaration of d::f() must be compatible with that of
> > c::f() in Command line code on line 1
> >
> >
> > I *really* think that this enforcements are no good idea and I _beg_
> > you that we leave this "area" to interfaces.
> +1
>
> In real live "C++" world I often have parent classes with function f()
> and an extended class which also uses the function name f(..) but with
> other, possibly class specific, variables, which then calls parent
> f()... I do not see a good reason to enforce that both functions must be
> exactly the same when extending, especially since c::f() does not get
> called automatically, _when_ overwriting it in class d.
It's quite a different thing in C++ as there you have method overloading
which PHP doesn't have. Therefore your argument doesn't hold here as
they are simply *two different* methods, and not an overriden one. In
your code that uses the derived class you can still use both methods
(one without, and the one with parameters).
Derick
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php