Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112678 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92687 invoked from network); 30 Dec 2020 19:56:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Dec 2020 19:56:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8DD091804C6 for ; Wed, 30 Dec 2020 11:31:14 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 30 Dec 2020 11:31:14 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id BBEA9B6B for ; Wed, 30 Dec 2020 14:31:13 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Wed, 30 Dec 2020 14:31:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=qnC8A4kMFq5gUUOJACkmlbCB23ujyNPrj5azE/3nX mc=; b=dJQ6E7uQLLnyd6yWYdkwx+zooaw2h9Ba7ZLjQRgCsflQ5IUiKAnC8rJGo AEjvnnjCGNADtPcFxTGQsKVfk5OQczdyIpOcy0KC1ZzpDJCGIPXBBRXyAFcHnbnF PZzIpSbeWVGxmUn+e4eCCGcyu0+2Hl7T/vUsZbln9v8dPOUoHzXKHWu7l9tuU1o5 2uh1hKgS50h9uXVqkWXKixR5yUyE/TmVBuy26KU7Vp34KmqAvuuc9QTUviOUT/dU 26MOzdh8aSFDW5GVCCHrifF1IhEt34fXiSBV2ObT1wyiL63L8H2FpEUNadxFcoTf tYi7l9I0nf5/JqMterTYvHY6M6s9w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvfedguddvhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0535D14200A2; Wed, 30 Dec 2020 14:31:13 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: <9ee07358-68bc-4578-a45a-4e23915ec102@www.fastmail.com> In-Reply-To: References: <1d0abb04-4987-43a9-85bc-bccc3bd6be9a@www.fastmail.com> <03108284-740a-4a5d-130f-15b2e67e9df9@mabe.berlin> <459d7ff7-e553-dce9-7d43-c3b1e772e572@gmail.com> <7f4fe9ca-1c20-6f69-cef0-a9718af742a3@gmail.com> Date: Wed, 30 Dec 2020 13:30:48 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Analysis_of_property_visibility,_immutability,_a?= =?UTF-8?Q?nd_cloning_proposals?= From: larry@garfieldtech.com ("Larry Garfield") On Wed, Dec 30, 2020, at 12:42 PM, Olle H=C3=A4rstedt wrote: > A more motivating example for uniqueness is perhaps a query builder. >=20 > ``` > $query =3D (new Query()) > ->select(1) > ->from('foo') > ->where(...) > ->orderBy(..) > ->limit(); > doSomething($query); > doSomethingElse($query); > ``` >=20 > In the above snippet, we don't know if doSomething() will change > $query and cause a bug. The issue can be solved with an immutable > builder, using withSelect(), withWhere(), etc, OR it's solved with > uniqueness, forcing a clone to avoid creating a new alias (passing > $query to a function creates an alias inside that function). The > optimisation is the same as in my previous example, avoiding copying > $query multiple times during build-up. For a query builder, I probably wouldn't make it immutable anyway, mysel= f. If you really want to force that doSomething() cannot modify the obj= ect that is otherwise mutable, calling doSomething(clone $query) already= works today and gets that net effect, provided that Query is safe to cl= one. (Vis, has no service dependencies, and if it has any dependent val= ue objects then it has a __clone() method that deep clones.) > >> The guarantee in both above snippets is that myfun() DOES NOT modif= y > >> $b before returning it. BUT with immutability, you have to copy $b > >> three times, with uniqueness only one. Yes, but with CoW those 3 copies are not that expensive, so we can most = of the time ignore them except as a very micro-optimization. (See previ= ous email.) --Larry Garfield