On Mon, Sep 19, 2011 at 10:40 AM, Gustavo Lopes <glo...@nebm.ist.utl.pt> wrote: > Em Sun, 18 Sep 2011 20:06:31 +0100, Stas Malyshev <smalys...@sugarcrm.com> > escreveu: > >> On 9/18/11 11:23 AM, Nikita Popov wrote: >>> >>> to tell you: I need this and that method accepting these and these >>> arguments to work correctly. If the signature isn't enforced, this >>> doesn't make sense anymore. You could just as well drop the signature >>> from abstract method definitions, as it's pointless then. >> >> No it is not. The signature tells "this method would accept certain >> arguments". If you call it with these arguments, it would work. However, >> there's no promise to never extend the cases where it works - it goes >> contrary to the whole point of OOP to say "I will never loosen preconditions >> on my methods". > > While this is true, we should be a bit pragmatic here. > > If the subclass method specifies less parameters, it is very likely a > mistake. It's not usual (certainly it's not more frequent than a mistake > being the case) for arguments to be simply intentionally ignored. In fact, I > don't know of any popular language that implements this type of > contravariance. Plus, consider the case in which the superclass takes an > argument by reference: > > function increment(&$foo) { $foo = $foo + 1; } > > It is obvious that in this case a subclass override that takes no arguments > cannot possibly satisfy the contract of the original method. That is to say, > by ref arguments are also used for postconditions. > > That said, I think the only rules worth implementing are: > > * Allow arguments with a supertype. For instance, this should give no > warning: > > <?php > class A {} > class B extends A {} > class C { function g(B $b) {} } > class D extends C { function g(A $a) { } } > > * Allow extra parameters with a default value (implemented): > > <?php > class C { function g($a) {} } > class D extends C { function g($a,$b=true) { } } >
could you check my second(lengthy) mail on this thread? I also tried to come up with the valid, and invalid signature changes. I forget to take references into account, so thanks for pointing that out. -- Ferenc Kovács @Tyr43l - http://tyrael.hu -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php