2010/8/19 Johannes Schlüter <johan...@schlueters.de>: > 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.
I suppose, when it comes to optional parameters, one can't rely on the transitive nature of class extension validity. You would need to iterate the definition chain of this method until it hits the signature that actually defines the "type" of the parameter(s) before throwing any messages. In my opinion as a regular developer, B::foo() would make a valid signature. > > johannes > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Tjerk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php