Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89980 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34487 invoked from network); 3 Jan 2016 19:39:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2016 19:39:08 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.220.49 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.220.49 mail-pa0-f49.google.com Received: from [209.85.220.49] ([209.85.220.49:35289] helo=mail-pa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/F2-28689-BD879865 for ; Sun, 03 Jan 2016 14:39:08 -0500 Received: by mail-pa0-f49.google.com with SMTP id do7so642735pab.2 for ; Sun, 03 Jan 2016 11:39:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=1W5E2ouUeKJ3iqWqS6EvBYe+ZbTY3771gLZ1G0lt7co=; b=gtM9ISOEYh6kotfCc67+nLnNw32QVOpN8Y3OVdIe93+UCo7l1Q+dQ41l8cAsvsLTD7 QXRmq3j5ykuqWr1yXQ7DhWNTPfCKL8T3/vMnIOOrPchWnPrB6OaLr/9W32M0sGcc3Ex7 N2c2hhcuZHy+6wNQ2JP7zNh3GY59GcOvcZcdSVRgD4AZOcDNKfYE3qYJiYsUJYEEpF/P kZTSxohVCU/mtl2XvQrXzkla2BdEM7MW9/bdIoSVLnXYA5/1xUWaMxu83jbJTDwxCMqn NJWocYwas9xTj33Sh2jeUarTeUvQwskFhAqgmVYs/gifQ/NCvtOM46uWcGzR/oyGSNg0 5elA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=1W5E2ouUeKJ3iqWqS6EvBYe+ZbTY3771gLZ1G0lt7co=; b=Kbnts4atwycDRAdVb/brwfME1BR57wb17Z9NCSW1PWFxvzVwtX2igpSIGxPRCcVi29 NN6z8Xbfb9o0AicTsswD94qiC9QUXwnBfAU9qwFvt46npBCHA8538xAw9ZYdaOU2oGTQ wvOXHaX41TrWphkXwp4lePTBUrFMoFKKzOI0ApkCwRFA2VYHD5MDpVohwrVecoX4n+Nb Lj3RalafWs0J305tv2ET88OniQF2lCOLmdm8jUabZHAJDhAc8k5wNb06gikWtyuCR9wB i7Ik/DppniW3S9mMzU60Q0RWyHVlUY67CrZWzkwHHINQXPCbiCU1ABWWqspZQ54JcSRx 85dw== X-Gm-Message-State: ALoCoQmLw3gCyVIW8JXOE6wKGMBaoAQxr6cR2Q8eOxrF6T9dgreBYncMeP1A+CVdtTBx2YeM0NZ+HIqoyI3qMqMhx4aEnc6cBQ== X-Received: by 10.66.150.37 with SMTP id uf5mr123643024pab.30.1451849945000; Sun, 03 Jan 2016 11:39:05 -0800 (PST) Received: from [10.0.1.43] (107-198-91-68.lightspeed.sntcca.sbcglobal.net. [107.198.91.68]) by smtp.gmail.com with ESMTPSA id n62sm52803052pfa.14.2016.01.03.11.39.03 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Jan 2016 11:39:03 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (13C75) In-Reply-To: Date: Sun, 3 Jan 2016 11:39:02 -0800 Cc: Sara Golemon , PHP internals , patriciotarantino@gmail.com Content-Transfer-Encoding: quoted-printable Message-ID: <501AD5B6-1CF2-4F3B-B394-F7AC8A8C1C75@golemon.com> References: To: Nikita Popov Subject: Re: [PHP-DEV] RFC Operator Overloading in Userspace From: php@golemon.com (Sara Golemon) > On Jan 3, 2016, at 02:11, Nikita Popov wrote: > Thanks for the proposal, Sara! A few questions to clarify: >=20 One point of order. It's Patricio's peoposal, I'm just helping him move it a= long. > 1. If an object implements __add__, will $a +=3D $b be equivalent to $a =3D= $a->__add($b) and ++$a be equivalent to $a =3D $a->__add(1)? This is how in= ternal operator overloading currently works (we have no separate overloads f= or assign ops). Will this RFC also work this way? To be quite honest, I'd rather it DIDN'T work that way. As I said to Stas, I= regard our current crossloading as broken since it forces new object creati= on when the statement visually calls for mutation. Semantically, what we do for GMP right now isn't sound, even if the distinct= ion doesn't seem to be breaking anyone. >=20 > 2. Regarding associativity, the RFC states "When both operands to a binary= expression implement operator overloading, the left-hand operand's handler w= ill be invoked. If only one of the two implement overloading, then that side= is invoked with the relative operation inverted as necessary." This sounds r= ather fishy to me, as not all operations are abelian. In particular __sub, _= _div, __pow and __concat are *usually* non-commutative. As such, the current= RFC does not appear to leave room for supporting things like 1/$complex or 1= -$complex or e**$complex. As such I wonder if these magic methods oughtn't b= e static methods with two operands. >=20 I did consider that as an alternate option. function overload_register($op, $lhtype, $rhtype, $callback); overload_type(ZEND_ADD, 'Complex', 'any', 'Complex::add'); This would get pretty expensive in terms of large lookup tables though, so I= 'm hesitant there. > 3. Relatedly, consider the situation where $obj1 op $obj2, where $obj1 and= $obj2 are instances of different classes, both of which have distinct overl= oads of the op operator. It so happens that the op-implementation of $obj1 d= oes not support operations against $obj2, while the op-implementation on $ob= j2 does support operations against $obj1. The op-implementation of $obj1 wil= l be invoked first -- will there be some way for it to signal "I don't suppo= rt this operation", thus allowing the op-implementation of $obj2 to be used?= >=20 I do like the idea of being able to signal type failures. Would a specific= exception be too heavyweight? Or just return "ConversionFailure" object in= stance or something... -Sara=