Hello George,

Tuesday, April 20, 2004, 8:57:31 PM, you wrote:

> On Apr 20, 2004, at 2:51 PM, Andrey Hristov wrote:

>> 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);
>> ?>

> The problem with this is that that integer may well be a string when 
> you look at it.  There's no good way to do this past discriminating 
> between scalar, array and object (by type, of course).   I personally 
> think that that is fine (adding an array typehint would be nice).

Somewhere at my server should be a patch for "array". For some reason
i was too lazy to ask for that to commit again before RC1. I you still
want this just ask Andi/Zeev again.

-- 
Best regards,
 Marcus                            mailto:[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to