Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92073 invoked from network); 7 Jan 2016 19:18:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2016 19:18:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.217.176 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.217.176 mail-lb0-f176.google.com Received: from [209.85.217.176] ([209.85.217.176:35008] helo=mail-lb0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/5E-21405-B0ABE865 for ; Thu, 07 Jan 2016 14:18:36 -0500 Received: by mail-lb0-f176.google.com with SMTP id bc4so212533034lbc.2 for ; Thu, 07 Jan 2016 11:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=gr1/c9M/LEkrHUKsrjSOIjPsYwcfEIjNBr35sPzpo0A=; b=ejyjgbhoCQcgaWGhXj92dPQZN/+U/UdmNVBU8MQninpt6PB23xh8RbcR2GEpXYWMgN v1wmhLLqUqOsRIEmijUsIO9JHYTyF1DMQjLA5ZD/kCShqS5ELd8Q3Gdx+WBCLh6HNxm6 jKCu3B1HrXe8Zxj7A3Xqp/NTqp6espki1UydWjiGUSifuLLB8Z5IM7zGV8QV+qh9qtUq qDIkE4VK0DpRcQu1RoCR/4ebjGSkCyLdzZCD6KCekvYA8/rj4RJIDr8yeEEJio4z7+Xq 1hjnSo0+nS5Jszkz/9fZy02zXsq6egcDa7WKNVi0lT4XyE2ojcvM7sPjgjX31IfoyLhK q9Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=gr1/c9M/LEkrHUKsrjSOIjPsYwcfEIjNBr35sPzpo0A=; b=GnHOXrNngJh9Q3N5r8Ji9Vw7gGoHB4iWyBQ8LPHeuzh7f2AHk1/vsGCGboKk4HMPA8 bFiR3TYX7nXtov7fzDxVqN9gnvk/Ck5vTAOfoSS5jcxTiBl8WY+ipbSF6M+WrItRNY0T LFZCL/nxL5Qk66n6jQP1awUn2tKuD5o4AwzXwTnE6o+UlgB2/KyIQR7+zToHbSS8X0LA c7h9em067KlOJ1dPQ18Lz/xJe5V6bnZj4BljhzVONwQvOrhk5QfmeKYFYRBjMy7WVR7t phPdt7Ui7WhrqubdUmXopBayJLRlCb9Dyqg53RRQldfElqibdvex9eGMICUsOAofBiYa NyVQ== X-Gm-Message-State: ALoCoQkToXUaoaYGOo/f8gXQNwC4ohgDA63CUybpCLujsQjIT8yoNdWf5sa037mzK2+mrbGBb2XkVtyUPPxDGTQTCtgAcTJ5xA== MIME-Version: 1.0 X-Received: by 10.112.132.66 with SMTP id os2mr26669659lbb.111.1452194312644; Thu, 07 Jan 2016 11:18:32 -0800 (PST) Sender: php@golemon.com Received: by 10.112.37.44 with HTTP; Thu, 7 Jan 2016 11:18:32 -0800 (PST) X-Originating-IP: [2620:10d:c090:200::6:546d] In-Reply-To: References: Date: Thu, 7 Jan 2016 11:18:32 -0800 X-Google-Sender-Auth: D2eu_UhsqQskNqIidqapU3YbsmU Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Differentiate op from assign-op in operator overloading From: pollita@php.net (Sara Golemon) On Thu, Jan 7, 2016 at 5:16 AM, Nikita Popov wrote: > GMP objects are, with the exceptions of gmp_setbit and gmp_clrbit, immutable > value objects. And yes, that's exactly what I would expect any object > representing a number to be. If $g->add(123) would modify $g instead of > returning a new object, that would be a major WTF moment for me (and for > that matter, make the usage very inconvenient.) > Sure, but if I called $g->assignAdd(123); then I would expect $g to be modified. That's the analogue to += so I while I don't disagree with your conclusion about add(), I do disagree with your analogy. > I don't get why you denounce immutable value objects as being "non-object > objects". Seems like very standard usage to me, and one that seems to be > increasingly preferred. > It's not their immutability which makes me call them that. It's the lack of anything you would normally see on an object: * No methods * No properties * No constants * Not initialized via `new` GMP objects are just resources by another name, and operator overloading got built around that model, rather than the model enjoyed by normal objects. That's why I denounce them as non-object objects. >> Leaving GMP out of the equation for now (and I think we need to have a >> longer discussion about this, but in another thread), I think the >> question which remains is: Do we want more non-object objects? >> Should, for example, SimpleXMLbe constrained by GMP's goals when >> implementing overloaded operators (no, I don't know what this would >> look like, it's just a for-instance). > > > If we leave GMP out of the equation, then yes, I agree. Whether $a op= $b > should create a new object or modify an existing one depends on the nature > of that object. For GMP (and Rational and Complex and Currency and most > other things that tend to be immutable value objects) I think the behavior > we currently provide is preferable (though I guess that is subject to > discussion), but for some other applications of operator overloading, this > choice wouldn't really make sense. > Agreed. The choice of mutability needs to be class specific, which is why I propose letting the class enforce it rather than dictating it from the engine and not giving the classes a choice. > It's currently already possible to distinguish this based on whether result > == op1. However we reserve the right (i.e. have some currently non-default > optimizations doing that) to have result == op1 in $a = $a + $b operations > as well, so this check is not robust. So, it would be good to change things > to pass in separate ZEND_ASSIGN_* flags. Will make the implementation even > more ugly though :) > Right, that optimization pass is slightly more complex. I haven't had the bandwidth to dig into it, but assuming a clean/efficient solution is available, would you be okay with the rest of the proposal overall? (Non-binding) -Sara