At 10:51 19/08/2010, 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?
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.
Zeev
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
