Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89977 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5792 invoked from network); 3 Jan 2016 10:12:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2016 10:12:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.177 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.160.177 mail-yk0-f177.google.com Received: from [209.85.160.177] ([209.85.160.177:35792] helo=mail-yk0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/A0-28689-1F3F8865 for ; Sun, 03 Jan 2016 05:12:01 -0500 Received: by mail-yk0-f177.google.com with SMTP id x67so223678542ykd.2 for ; Sun, 03 Jan 2016 02:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2T9wd6kpbZ3AvC4fFAmMuVgf0B6q5KwvUJ/sHhy2J6c=; b=yP4646K8IH7vk4hA3hu5+eFrpB2/581SP2w1NNd+BPow7c0qKiZyo5nHaPx7XrXg58 pr3aEQdw+RLVJGd0REHo/E8EMbcT4kgRb6JhgdHXImXLFazKbPKlVVqhB/z4SWkyPInP MoK/nu8LHB/Cr2hee8OlO5vMw+qnng9ExFnapGlzgSmfG9bAdKzPv5aYYG0TD9C/KRMk iCKtq5eiCnlccs4NWRKNl/ti+Y6/fMf/Gsj22O6ad2FQrpVY2+5VSZ7wsZFI0Yzl2pLX 3Fi5HgTcoYKHuA+1ZGa/wdr8vxvI4Y/ZzgCskSbRWwRpYT1Vam7A8lsTJPhNYOTsZUKd 2F6g== MIME-Version: 1.0 X-Received: by 10.129.50.12 with SMTP id y12mr58231526ywy.305.1451815918015; Sun, 03 Jan 2016 02:11:58 -0800 (PST) Received: by 10.129.148.70 with HTTP; Sun, 3 Jan 2016 02:11:57 -0800 (PST) In-Reply-To: References: Date: Sun, 3 Jan 2016 11:11:57 +0100 Message-ID: To: Sara Golemon Cc: PHP internals , patriciotarantino@gmail.com Content-Type: multipart/alternative; boundary=001a11414910129f9005286b3c86 Subject: Re: [PHP-DEV] RFC Operator Overloading in Userspace From: nikita.ppv@gmail.com (Nikita Popov) --001a11414910129f9005286b3c86 Content-Type: text/plain; charset=UTF-8 On Sun, Jan 3, 2016 at 3:14 AM, Sara Golemon wrote: > Patricio Tarantino has asked me to help him propose Operator > Overloading in PHP 7.1 (based in part on my operator extension in > PECL). I think we can expose this to usespace as magic methods with > very little overhead (the runtime check and dispatch is already there, > after all). > > I do think that the "Future Expansion" section bears following through > with as well, but the basic set of methods already hooked for GMP > would be a nice start. > > https://wiki.php.net/rfc/operator-overloading > > -Sara > Thanks for the proposal, Sara! A few questions to clarify: 1. If an object implements __add__, will $a += $b be equivalent to $a = $a->__add($b) and ++$a be equivalent to $a = $a->__add(1)? This is how internal operator overloading currently works (we have no separate overloads for assign ops). Will this RFC also work this way? 2. Regarding associativity, the RFC states "When both operands to a binary expression implement operator overloading, the left-hand operand's handler will be invoked. If only one of the two implement overloading, then that side is invoked with the relative operation inverted as necessary." This sounds rather 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 be static methods with two operands. 3. Relatedly, consider the situation where $obj1 op $obj2, where $obj1 and $obj2 are instances of different classes, both of which have distinct overloads of the op operator. It so happens that the op-implementation of $obj1 does not support operations against $obj2, while the op-implementation on $obj2 does support operations against $obj1. The op-implementation of $obj1 will be invoked first -- will there be some way for it to signal "I don't support this operation", thus allowing the op-implementation of $obj2 to be used? Thanks, Nikita --001a11414910129f9005286b3c86--