RE: [PHP-DEV] RfC: rethink OO inheritance strictness
| From: | Soenke Ruempler | Date: | Fri, 21 Jul 2006 09:58:44 +0000 |
| Subject: | RE: [PHP-DEV] RfC: rethink OO inheritance strictness | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-24815@lists.php.net to get a copy of this message | ||
Derick Rethans <mailto:derick@php.net> wrote on Friday,
July 21, 2006
11:31 AM:
> It's quite a different thing in C++ as there you have method
> overloading which PHP doesn't have. Therefore your argument doesn't
Exactly the point. It's parameter polymorphism in C++/Java.
> 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).
To be compatible, the only thing you have to do is adding standard
values to derived methods' parameters:
$ php -d"error_reporting=8191" -r 'class c{function f(){}} class d
extends c{function f($a){}}';
Strict Standards: Declaration of d::f() should be compatible with that
of c::f() in Command line code on line 2
$ php -d"error_reporting=8191" -r 'class c{function f(){}} class d
extends c{function f($a = null){}}';
$ [no error]
This behaviour makes sense to me.
-soenke