Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14572 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53784 invoked by uid 1010); 3 Feb 2005 16:42:54 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 53672 invoked from network); 3 Feb 2005 16:42:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2005 16:42:52 -0000 X-Host-Fingerprint: 80.239.127.2 unknown Windows 2000 SP4, XP SP1 Received: from ([80.239.127.2:2872] helo=utvikling.adstate.net) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id D9/47-29932-BDF42024 for ; Thu, 03 Feb 2005 11:22:51 -0500 Message-ID: <02d801c50a0c$93bb7b30$a900000a@adstate.local> To: References: <5.1.0.14.2.20050201111730.0299da70@localhost> Date: Thu, 3 Feb 2005 17:22:37 +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?=) > 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. That's only confusing if you don't know that operator overloading is possible. In C++, it's perfectly natural to be able to e.g. add values of user-defined types. It also enables generic code, such as: function some_calculation($num1, $num2) { $num1+=1; $num2+=num1; ... } This would then work for any object (built-in type or user-defined type (class)) having operator+= defined. Why this would be confusing is beyond me... Could you enlighten me? Specifically, do you find the following: $result=$c1.multiply($c2).divide($c1.add($c2)); less "confusing" than: $result=($c1 * $c2) / ($c1 + $c2); ? >Use C++/Java if you want this... Why would it be ok there, but not in PHP? It also exists in other scripting languages, such as Python and Perl. BTW, as another poster pointed out, it doesn't exist in Java, either, except for the "+" exception for strings. I think omitting that is a case of "throwing the baby out with the bath water". Yes, used incorrectly, operator overloading can be confusing, but that's also the case for more or less any language feature, and we don't ban them. It's no less confusing having the member function "add()" perform subtraction, as it is to let the "+" do that. Regards, Terje