Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14580 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23606 invoked by uid 1010); 3 Feb 2005 18:41:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 15264 invoked from network); 3 Feb 2005 18:37:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2005 18:37:57 -0000 X-Host-Fingerprint: 217.13.4.94 bgo1smout1.broadpark.no Solaris 9 Received: from ([217.13.4.94:60320] helo=bgo1smout1.broadpark.no) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id 56/98-13762-66F62024 for ; Thu, 03 Feb 2005 13:37:27 -0500 Received: from bgo1sminn1.broadpark.no ([217.13.4.93]) by bgo1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IBC001FYM5NBPQ0@bgo1smout1.broadpark.no> for internals@lists.php.net; Thu, 03 Feb 2005 19:32:11 +0100 (CET) Received: from pc ([80.203.129.71]) by bgo1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with SMTP id <0IBC00EGOMIJZ560@bgo1sminn1.broadpark.no> for internals@lists.php.net; Thu, 03 Feb 2005 19:39:56 +0100 (CET) Date: Thu, 03 Feb 2005 19:39:52 +0100 To: internals@lists.php.net Message-ID: <00bc01c50a1f$c000a9a0$0300000a@pc> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Mailer: Microsoft Outlook Express 6.00.2800.1437 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT X-Priority: 3 X-MSMail-priority: Normal References: <5.1.0.14.2.20050201111730.0299da70@localhost> <42020015.5090209@cschneid.com> <02d901c50a0c$b2c0c3f0$a900000a@adstate.local> Subject: Re: [PHP-DEV] PHP 5.1 - operator overloading From: tslettebo@broadpark.no (=?iso-8859-1?Q?Terje_Sletteb=F8?=) > TS>>If $a is an object of a class, then they would both be in the class > TS>>definition. One is called "add", and the other is called "operator+". What's > TS>>the problem with that? > > The problem is that you can't really know what $a is - PHP is typeless. When you say "typeless", i think you mean "not statically typed". I've been through this discussion elsewhere - a variable will at any one time have a well-defined type (or unset), which you may overload on, so the language is definitely not typeless. An example of a typeless (or single type language, if you like) language is BCPL, where there was only one type, the machine word. As mentioned in another posting, operator overloading also exists in other dynamically typed languages, such as Python and Perl. > You'll have to trace all the program up to $a's assignment and hope you > didn't miss reassignment on the way. Yes, variables are dynamically typed, but when you call a function, you typically have an idea of what its type is. Otherwise, the "type hints" for PHP 5 would be pointless! By your argument. > TS>>It would if operator overloading was allowed on free functions (as it is in > TS>>C++). E..g: > > You can't do it like in C++, because in C++ function signature includes > argument types, and in PHP it does not. That's right, so we'd really need function overloading to be able to use the free function form, which I think is another good idea (function overloading). > I.e., you can't write two > operators - one for complex+int and one for complex+complex. In general, > it's too much trouble for too little gain Well, you're certainly entitled to your opinion, but others, including me, think it's worth it. > - except for select things like > complex and matrices (and maybe two more things like this) I don't see any > value in having, say, + overloaded. Using good old methods will never fail > you. Neither will assembly code. Regards, Terje