Re: Method overloading by method signature

From: Date: Sat, 13 Oct 2007 21:20:12 +0000
Subject: Re: Method overloading by method signature
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-32750@lists.php.net to get a copy of this message
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 <hans.moog@mkj-computing.de> 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:indeyets@gmail.com] > 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 <hans.moog@mkj-computing.de> 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/

« previous php.internals (#32750) next »