Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14570 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5791 invoked by uid 1010); 3 Feb 2005 16:23:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5768 invoked from network); 3 Feb 2005 16:23:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2005 16:23:47 -0000 X-Host-Fingerprint: 80.239.127.2 unknown Windows 2000 SP4, XP SP1 Received: from ([80.239.127.2:2876] helo=utvikling.adstate.net) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id 6D/47-29932-21052024 for ; Thu, 03 Feb 2005 11:23:46 -0500 Message-ID: <02d901c50a0c$b2c0c3f0$a900000a@adstate.local> To: References: <5.1.0.14.2.20050201111730.0299da70@localhost> <42020015.5090209@cschneid.com> Date: Thu, 3 Feb 2005 17:23:30 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Subject: Re: [PHP-DEV] PHP 5.1 From: tslettebo@broadpark.no (=?iso-8859-1?Q?Terje_Sletteb=F8?=) > Derick Rethans wrote: > > On Thu, 3 Feb 2005, Sebastian Bergmann wrote: > > > >>Derick Rethans wrote: > >>>This adds operator overloading to user classes? > >> Yes, have a look at Johannes' Complex example [1]. > > > > Okay, mega Yuck then. Although it looks cool, I consider it as a bad > > practise. It confuses the hell out of people that they can add two > > objects. Use C++/Java if you want this... > > I couldn't agree more. I like PHP not because it is the most compact or > flexible of all languages but because the syntax is quite simple. > > Try explaining someone who just learned PHP and doesn't know your code > where to find the implementation of > $c = $a + $b; > as opposed to > $c= $a->add($b); > or > $c = Complex::add($a, $b); If $a is an object of a class, then they would both be in the class definition. One is called "add", and the other is called "operator+". What's the problem with that? > Another little thought how confusion can easily happen with operator > overloading: $b = $a + 42; works but $b = 42 + $a; doesn't, i.e. the > overloaded addition isn't commutative. It would if operator overloading was allowed on free functions (as it is in C++). E..g: function operator+(complex $a, complex $b) { return new complex($a.real + $b.real, $a.imag + $b.imag); } The binary operators are recommended to to free functions, for this reason, in C++. Regards, Terje