Re: OO Parameter Checking

From: Date: Fri, 29 Feb 2008 17:44:44 +0000
Subject: Re: OO Parameter Checking
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-35865@lists.php.net to get a copy of this message
Hi!
1) The current checks are IMHO too strict regarding default values for parameters: An inheriting class can add default values to a parameter without breaking the protocol: class A { function foo($x) { ... } } class B extends A { function foo($x = 42) { ... } } should be allowed. Only if there are fewer parameters in B::foo or if
I think this makes sense. In fact, if B::foo() has less parameters it might be OK too, since B would just ignore extra parameters (and in fact it could do it anyway :)
2) The current checks are IMHO too strict regarding static functions: Static functions are not part of an instance's protocol (they can not be passed around) and should be left out of the check the same way constructors are ignored. The use case for this is a factory method: class A { static function factory($size) { ... } } class B extends A { static function factory($size, $color) { ... } }
Not sure about this - might be some nasty surprises here if you substitute class B for class A. Anyway, why not call B's function factoryB or something? If you are only going to call it directly by name, there's no difference. It would be nice if you made separate patches for each feature. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#35865) next »