I consider having type in the declaration of a method a bad idea and
this thread just prove it. You can also read this: http://gbracha.blogspot.com/2009/09/systemic-overload.html On 08/19/2010 10:32 AM, Johannes Schlüter wrote: On Thu, 2010-08-19 at 01:13 -0700, Stas Malyshev wrote:Hi!I was under the impression that, in order for inheritance to provide proper polymorphism, overridden methods should share the parent's method signature, although they can have additional optional arguments.Your impression is wrong. Overriden method should have _compatible_ signature - i.e. accept any argument set that parent object accepted. Nothing requires it to have the same signature.Let|s take a look at making it one step more complex: class A { public function foo(Foo $a = null) {} } class B extends A { public function foo() {} } class C extends B { public function foo(Bar $a = null) {} } Here B::foo() is compatible with A:foo() and as the parameter is optional C::foo() is compatible with B::foo(). But C::foo() is no more compatible with A::foo(). So I consider the message good and correct. johannes --
|
Title: Document sans nom
- Re: [PHP-DEV] inheritance check ... Stas Malyshev
- Re: [PHP-DEV] inheritance check too strict? Johannes Schlüter
- Re: [PHP-DEV] inheritance check too stric... Nathan Rixham
- Re: [PHP-DEV] inheritance check too s... Ryan Panning
- Re: [PHP-DEV] inheritance check ... Ionut G. Stan
- Re: [PHP-DEV] inheritance ch... Zeev Suraski
- Re: [PHP-DEV] inheritance ch... Nathan Rixham
- Re: [PHP-DEV] inheritance ch... Chris Stockton
- Re: [PHP-DEV] inheritance ch... Nathan Rixham
- Re: [PHP-DEV] inheritance check too stric... Tjerk Anne Meesters
- Re: [PHP-DEV] inheritance check too stric... mathieu.suen
- Re: [PHP-DEV] inheritance check too stric... Stas Malyshev
- Re: [PHP-DEV] inheritance check too strict? Zeev Suraski
- Re: [PHP-DEV] inheritance check too strict? Stas Malyshev
- Re: [PHP-DEV] inheritance check too strict? postmaster
- Re: [PHP-DEV] inheritance check too strict? Nathan Rixham
- Re: [PHP-DEV] inheritance check too strict? Jean-Sébastien H.
- RE: [PHP-DEV] inheritance check too stric... Jonathan Bond-Caron
- Re: [PHP-DEV] inheritance check too s... Nathan Rixham
- RE: [PHP-DEV] inheritance check ... Jonathan Bond-Caron
- Re: [PHP-DEV] inheritance ch... Reindl Harald