Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1616 invoked from network); 7 Jan 2016 14:04:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2016 14:04:14 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.90 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.90 blu004-omc2s15.hotmail.com Received: from [65.55.111.90] ([65.55.111.90:56965] helo=BLU004-OMC2S15.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/0E-21755-B507E865 for ; Thu, 07 Jan 2016 09:04:12 -0500 Received: from BLU436-SMTP173 ([65.55.111.71]) by BLU004-OMC2S15.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Thu, 7 Jan 2016 06:04:08 -0800 X-TMN: [KlnwY5i6tg2hEbON4j6c3M9ypmCKnaIZ] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\)) In-Reply-To: Date: Thu, 7 Jan 2016 15:04:04 +0100 CC: PHP internals , Nikita Popov Content-Transfer-Encoding: quoted-printable References: To: Sara Golemon X-Mailer: Apple Mail (2.3096.5) X-OriginalArrivalTime: 07 Jan 2016 14:04:06.0197 (UTC) FILETIME=[45771E50:01D14954] Subject: Re: [PHP-DEV] [RFC] Differentiate op from assign-op in operator overloading From: bobwei9@hotmail.com (Bob Weinand) > Am 04.01.2016 um 01:37 schrieb Sara Golemon : >=20 > This is a separate proposal from the userspace operator overloading I > put up for Patricio yesterday and aims to fix what I see as a bug in > our operator overloading implementation (though some may disagree). >=20 > It specifically only seeks to differentiate const operations which > produce a new value from mutations which alter an existing overloaded > object. >=20 > https://wiki.php.net/rfc/assignment-overloading Hey, I think this RFC is attempting to solve the wrong problem... Let me = explain why: a) What do you do in cases like: $a =3D gmp_init(125); $b =3D $a; $b +=3D 10; $a and $b hold the same object reference, so we'd need to do an implicit = clone (separation) before passing it to the assign ops, or we are going = to break the immutable-value-object assumption. That risks to be be problematic. As long as it is internal, we could = deal with it internally. When we leak operator overloading to userland, = not so much. b) The main goal is to not needing copies when unnecessary. This could = then as well apply to simple cases like: $a =3D gmp_init(125); $b =3D $a + 10; /* $a isn't used anymore later */ or just explicit: $a =3D $a + 10; # instead of $a +=3D 10; // under some circumstances = that may be more readable... With opcache analysis we'll probably be able to determine when we won't = use the symtable directly (via varvars, get_defined_variables() etc.), = where this will present another valuable optimization possibly. At that point you would possibly rather explicitly check: "are we at the = end of a variable range (if CV) and the refcount of the object =3D=3D = 1?" and eventually forward that information to userland as optional = third param. Which would give you the most optimization possible; and even applicable = in the example Nikita provided with sets. Example: function or($a, $b, $mutable =3D OVERLOAD::NO_REUSE) { switch ($mutable) { case OVERLOAD::REUSE_OP1_OP2: case OVERLOAD::REUSE_OP1: $a->add($b); return $a; case OVERLOAD::REUSE_OP2: $b->add($a); return $b; default: $a =3D clone $a; $a->add($b); return $a; } } Bob=