Re: inheritance check too strict?

From: Date: Thu, 19 Aug 2010 08:06:28 +0000
Subject: Re: inheritance check too strict?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-49448@lists.php.net to get a copy of this message
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

« previous php.internals (#49448) next »