Re: inheritance check too strict?
| From: | Zeev Suraski | Date: | Thu, 19 Aug 2010 15:10:11 +0000 |
| Subject: | Re: inheritance check too strict? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49456@lists.php.net to get a copy of this message | ||
At 10:51 19/08/2010, Stas Malyshev wrote:
Hi! I recently noticed this code: <?php error_reporting(E_ALL | E_STRICT); class ObjParent {As others noted I also think that this warning is correct. Code that deals with ObjParent objects is allowed to call to set() with a parameter. It's also supposed to be able to treat ObjChild objects transparently, because they're specialized of ObjParent. If this function signature was allowed - it can end up calling ObjChild::set() with an argument - which ObjChild() doesn't support. The other way around - making ObjChild::set() more support more signatures than the signature it's 'overriding' - makes perfect sense and is allowed. Regarding the other issue that was raised here, I didn't recall we made is_a() checks on class type hints during signature validation, but if we do - it should be done using the same rules - a child class's signature must be at least as lax as it's parent - or more. Zeevpublic 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?