Re: Multi-Method Dispatch in PHP 5.1?
| From: | Andrey Hristov | Date: | Wed, 21 Apr 2004 06:47:30 +0000 |
| Subject: | Re: Multi-Method Dispatch in PHP 5.1? | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-9442@lists.php.net to get a copy of this message | ||
Andrey Hristov wrote:
<?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); } protected function doSomething_objectFubar($fub) { $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 (FALSE !==($c_name = get_class($v))) { $method_name .= $c_name; } } 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); $a->doSomething($a); ?> OTOH hinting for array (internally) will be nice also. Cheers, Andrey..... ..... ah, the code has an error and I found more efficient way (for objects no need of string compare):