On 19/08/10 08:51, Stas Malyshev wrote:
> Hi!
>
> I recently noticed this code:
>
> <?php
> error_reporting(E_ALL | E_STRICT);
>
> class ObjParent {
>     public function set($param2 = ''){ }
> }
>
> class ObjChild extends ObjParent {
>         public function set(){ }
> }
>
> produces a E_STRICT warning. I don't really see a point in it -
> there's no problem whatsoever with child function ignoring some
> arguments from parent call. Anybody could explain why this check is
> there?
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.
Otherwise, if you're passed an ObjChild when you are treating it as an
ObjParent, you could get unexpected behaviour if it ignores $param2 when
you decide to specify it. PHP doesn't complain about a programmer
passing too many arguments to the function as far as I recall, so this
sort of bug can be easy to overlook.

I hope that makes sense :-/


Dave

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to