Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9458 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17021 invoked by uid 1010); 21 Apr 2004 11:26:13 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16986 invoked from network); 21 Apr 2004 11:26:13 -0000 Received: from unknown (HELO spawn.leetspeak.org) (217.28.101.185) by pb1.pair.com with SMTP; 21 Apr 2004 11:26:13 -0000 Received: (qmail 16882 invoked from network); 21 Apr 2004 13:26:35 +0200 Received: from pd9e0388e.dip.t-dialin.net (HELO leetspeak.org) (cm@217.224.56.142) by molly.zwonet.de with AES256-SHA encrypted SMTP; 21 Apr 2004 13:26:35 +0200 Message-ID: <40865A4C.7090505@leetspeak.org> Date: Wed, 21 Apr 2004 13:26:04 +0200 User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net References: <40858E36.2070200@cschneid.com> <40860773.6070406@leetspeak.org> <40863B3F.2060700@cschneid.com> In-Reply-To: <40863B3F.2060700@cschneid.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Multi-Method Dispatch in PHP 5.1? From: cm@leetspeak.org (Michael Walter) Christian Schneider wrote: > Michael Walter wrote: > >> How exactly do you think are default parameters related to the issue, >> anyway? > > > Java uses multi-method dispatch to work around missing default values: > function foo($a, $some_flag) { ... } > function foo($a) { foo($a, false); } > instead of > function foo($a, $some_flag = false) { ... } Well yeah, we were presumably talking about different things, hence the question :) What you are talking about is a certain kind of "compile time" polymorphism, where the appropriate method is chosen at compile time. I was referring to "runtime" polymorphism, i.e. the _dispatch_ is done on not only on one type (as with the type of the $object in an $object->method() call), but on 2 types (as in multimethod($rect,$circle)). I'm pretty sure that Sebastian was referring to the same mechanism, as his example would need dispatch on 2 types, too, in order to work. Also, I think functions which are dispatched using multiple types might as well be global functions, because usually (?) there is no such thing as a "first class" and "second class" dispatchee (is that a word?). For instance, consider: function collides(Rect $rect, Rect $circle) { ... } function collides(Rect $rect, Circle $circle) { ... } > >> I assume you are you aware of what dynamic dispatch is trying to solve > Whatever example I'd give you'd probably say it's not the relevant one. Naw, I didn't want to piss you of, just check whether we were dealing with the same thing. :) > But if you give me a use case for dynamic dispatch I show you how I'd do > it in PHP. Maybe we should take that off list though and present just > the result of our research :-) Yeah, well, you will show me the visitor pattern, which is an inferior work-around for the lack of multiple dispatch (because it only works well for closed sets of classes, although having it work for an open set of classes like with dynamic dispatch on the $this 'pointer' is desirable). For a typical example, you might want to check out the Gang of Four book (Visitor pattern, which simulates multiple dispatch for multiple = 2) or consider above's collides() example. The main difference between the 'isinstance' solution someone on this list posted is that you do not have to _modify_ a big large collides() function, but you just keep adding the new cases. This is like with inheritance -- you use inheritance and dynamic dispatch on the $this 'pointer' in order to avoid series of 'isinstance' checks. Anyway, I'm not really sure whether dynamic dispatch is appropriate in PHP myself, but I felt like pointing out the differences between static and dynamic dispatch might be important. ;) Cheers, Michael