Quoting Sebastian Bergmann <[EMAIL PROTECTED]>: > Since we introduce class type hints in PHP 5.0 I think it would be a > good thing [tm] to add multi-method dispatch in PHP 5.1. > > What I mean by this would be to allow for the following: > > class Foo { > public function doSomething(Foo $foo) {} > > public function doSomething(Bar $bar) {} > } > > How complicated would this be to implement? > Hi, yesterday while waiting at the UBahn (Metro) station I came to the idea such thing can me made in userland. func_get_args() can help combined with get_type() for simple types. if it's class than => use also the class name if you want.
<?php class fubar { protected function doSomething_integer_integer_double($i1,$i2,$f) { $a = func_get_args();var_dump(__METHOD__, $a); } protected function doSomething_integer_double($i,$f) { $a = func_get_args();var_dump(__METHOD__, $a); } public function doSomething() { $args = func_get_args(); $method_name = __FUNCTION__; foreach ($args as $v) { $method_name .= "_".gettype($v); } if (method_exists($this, $method_name)) { return call_user_func_array(array($this, $method_name), $args); } } }//class fubar $a = new fubar(); $a->doSomething(1, 2.0); $a->doSomething(3,4, 5.0); ?> Cheers, Andrey -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php