As long as you only got one method per name it doesn't change things, so it wouldn't brake backward compatibility and old functions would still behave like expected (so it is not incompatible).
But if you want to be more strict and limit the coder to use your functions only with a specific parameter signature (and thats the only reason to use type hints - to ensure the method is used correctly and build more robust applications), it is better to tell the coder that he made a mistake than just going on and guessing which method to call. The new PHP5 object model introduces signature checking (yay!) but since PHP doesn't allow overloading a great deal of flexibilty was lost in this move (boo!). No longer can you override a method & provide an incompatible signature. This mixture of strict OO + PHP's traditional loose typing is really shooting PHP in the foot. I think, that this ist the reason why nearly nobody uses this great new feature (to ensure that the passed parameters are correct), because when he does, he isn't able to provide different ways to use a method anymore. And allowing signature checks would really enhance php's security because an integer id (for example) can never be used to insert malicious sql into an sql statement and by that create an sql injection. You wouldn't have to put a mysql_escape_string (or integer typecast) around every single parameter anymore because you would be able to rely on an integer id, really being an integer id without messing around with thousands of custom checks (that would even boost performance since string operations are always a bit slow). And like i already said - this "new feature" wouldn't make php a strong typed language (you would still have all the possibilities of using variables as different types), it would just offer the coder a method to write more strict method declarations that would definitly enhance the performance, security an robustness of applications. -----Ursprüngliche Nachricht----- Von: Alexey Zakhlestin [mailto:[EMAIL PROTECTED] Gesendet: Sonntag, 14. Oktober 2007 10:04 An: Hans Moog Cc: internals@lists.php.net Betreff: Re: [PHP-DEV] Method overloading by method signature On 10/14/07, Hans Moog <[EMAIL PROTECTED]> wrote: > It shows an error that fun1 is not implemented for the signature of the > passed parameters. > > But you could still provide a method that matches any number and type of > parameters by adding the following method declaration. Well, this looks exactly like incompatibility to me, because currently any function accepts any number of parameters (and you get non-explicit ones by using func_get_args()) > > /** > * This method accepts parameters of any type and any count. > */ > public function fun1($parameters ...) { > /* > * array(3) { > * [0] => string(1) "a" > * [1] => string(2) "b" > * [2] => string(3) "c" > * } > */ > var_dump($parameters); > } > > > The "..." notation (making it possible to have a dynamic count of parameters > of the given type (missing typehint automatically chooses mixed)) is only > allowed for the last parameter. > > So method defintions like the following one are also possible: > > > public function fun1(string $firstParam, string $remainingParameters ...) { > /* > * string(1) "a" > */ > var_dump($firstParam); > > /* > * array(3) { > * [0] => string(1) "b" > * [1] => string(2) "c" > * } > */ > var_dump($remainingParameters); > } > > -----Ursprüngliche Nachricht----- > Von: Alexey Zakhlestin [mailto:[EMAIL PROTECTED] > Gesendet: Samstag, 13. Oktober 2007 23:20 > An: Hans Moog > Cc: internals@lists.php.net > Betreff: Re: [PHP-DEV] Method overloading by method signature > > can your patch handle the following situation? how? > > class A > { > public function fun1($a) > { > //… > } > > public function fun1($a, $b) > { > //… > } > } > > $a = new A(); > $a->fun1('a', 'b', 'c'); // which method is called here? > > On 10/14/07, Hans Moog <[EMAIL PROTECTED]> wrote: > > Why would it be incompatible with php's dynamic nature? (I already heard > > many people saying "that this is not the php way") But why ? Don't you like > > it or do you think it is just not possible to be implemented in php? > > > > I could provide a patch that makes it possible (even with complete > > visibility and inheritance rules). We already use it and it saves us a lot > > of code. > > > > I think it is better than the '$x = "defaultValue"' kind of way to accept > > different count and types of parameters because it is MUCH more expressive > > and intuitive. > > > > It wouldn't even break backward compatibility beause it is just > > "syntactical sugar" to checking the variable types manually and then > > dispatching to the right behaviour. > > > > -----Ursprüngliche Nachricht----- > > Von: Alexey Zakhlestin [mailto:[EMAIL PROTECTED] > > Gesendet: Samstag, 13. Oktober 2007 22:22 > > An: Hans Moog > > Cc: internals@lists.php.net > > Betreff: Re: [PHP-DEV] Method overloading by method signature > > > > Hans, such overloading would be incompatible with php's dynamic nature > > As far as I remember, even type-hinting for basic-types (strings, > > integers) was rejected > > > > On 10/13/07, Hans Moog <[EMAIL PROTECTED]> wrote: > > > Will method overloading by method signature be implemented in php6 or > > > even php 5.3? > > > > > > > > > > > > Example: > > > > > > <?php > > > > > > namespace xyz; > > > > > > > > > > > > import core::TestClass; > > > > > > > > > > > > class Test extends TestClass { > > > > > > public string function test(integer $int) { > > > > > > return "Hi"; > > > } > > > > > > > > > > > > public integer function test(string $string, integer $int) { > > > > > > return $int; > > > } > > > } > > > > > > ?> > > > > > > > > > > > > I think this would be a very big advantage and would help developers to > > > write better code. > > > > > > > > > > > > -- > > Alexey Zakhlestin > > http://blog.milkfarmsoft.com/ > > > > > > > > > -- > Alexey Zakhlestin > http://blog.milkfarmsoft.com/ > > > -- Alexey Zakhlestin http://blog.milkfarmsoft.com/