Re: Multi-Method Dispatch in PHP 5.1?

From: Date: Wed, 21 Apr 2004 06:27:22 +0000
Subject: Re: Multi-Method Dispatch in PHP 5.1?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-9441@lists.php.net to get a copy of this message
George Schlossnagle wrote:
.. $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). George
Hi George, an integer can be represented as string or the float can be also a string and in this case it won't work but it works for situation where the programmer knows what he is doing. Joe average won't need the language feature thus won't need to implement it even in userland. Sebastian's case was about classes and an object cannot be anything else but object protected function doSomething_objectBar_objectFoo($bar, $foo) {}
        public function doSomething() {
                $args = func_get_args();
                $method_name = __FUNCTION__;
                foreach ($args as $v) {
$type = $v;
                        $method_name .= "_".gettype($v);
if ($type === "object") $method_name .= get_class($v);
                }
Of course this is quite fast :/ Cheers, Andrey

« previous php.internals (#9441) next »