Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112720 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27708 invoked from network); 3 Jan 2021 03:01:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2021 03:01:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA3D31804D4 for ; Sat, 2 Jan 2021 18:37:10 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from premium76-4.web-hosting.com (premium76-4.web-hosting.com [162.213.253.126]) (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 ; Sat, 2 Jan 2021 18:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pmjones.io; s=default; h=To:References:Message-Id:Content-Transfer-Encoding:Cc:Date: In-Reply-To:From:Subject:Mime-Version:Content-Type:Sender:Reply-To:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Archive; bh=m5rNgfCx2L5UVr0migmGV1UepIWagAjlr5xYoIwFqMc=; b=ehNWL1Pz18bjGnnvhPLSM44pHm uovOe0wtPDUOyCpyLqtdKNFNwO4E7NEA3OcQSyg9m1lWmiC5jTonIoBydKiWUQIOiK/LGuqE7L4It AKeXWfBCLaffAXEmFM+n6QmYYXhAILJ6VjFLTFYPDurR3NpfglGlnLHbrNNOFgkdecKCyz7LCL3ii A7exi5xieLQmsYmtfxHqanGj1WNZtRwdEJA4PvPbmSa+f3JILHpJ9IyC5pHArTvvkzy8aLQyI3uus Ztjz/QF0bmxZ7NIc6wLyJ17UZ2Ntwe09KR05KtC2XAen0YmVGMUjGYE9NRwT+vdLBsvecKhNtVSui MkT7zJGQ==; Received: from 107-223-28-39.lightspeed.nsvltn.sbcglobal.net ([107.223.28.39]:56775 helo=samurai.attlocal.net) by premium76.web-hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvtGS-0013iv-U8; Sat, 02 Jan 2021 21:37:09 -0500 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: Date: Sat, 2 Jan 2021 20:37:03 -0600 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <643FECB5-A7EE-4EDB-A473-F14971CE083F@pmjones.io> 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> <30906866-1971-8395-05a0-fd78d054bb89@gmail.com> <0C621FEF-B76F-41F5-A5A8-E6F24D69DD3D@pmjones.io> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.1) X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - premium76.web-hosting.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pmjones.io X-Get-Message-Sender-Via: premium76.web-hosting.com: authenticated_id: pmjones@pmjones.io X-Authenticated-Sender: premium76.web-hosting.com: pmjones@pmjones.io X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched Subject: Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals From: pmjones@pmjones.io ("Paul M. Jones") Hi Rowan and all, I apologize in advance for the wall-of-text; the short questions lead to = long answers. > On Jan 2, 2021, at 12:56, Rowan Tommins = wrote: >=20 > On 01/01/2021 20:31, Paul M. Jones wrote: >=20 >> The complaints against the incomplete and inconsistent immutability = of PSR-7 have merit. >=20 > The big mistake of PSR-7, in my view, is mixing immutable objects with = streams, which are inherently mutable/stateful. (/me nods along) Streams were noted as the one explicit exception to immutability in = PSR-7. Looking back on it, that should have been a sign to us that = immutability should not have been a goal. (Re: PSR-7 but not re: immutability, there is at least one more mistake = born of the original intent, that seemed reasonable at the time but in = hindsight was another poor decision: it combines the concerns of the = HTTP message with the concerns of middleware communication. This = observation is attributable to [deleted] at Reddit ... = https://www.reddit.com/r/PHP/comments/5ojqr0/q_how_many_psr7_implementatio= ns_exist_a_zero/dcjxtxl/ ... stating "[T]he true intent of PSR-7 [is] not to be an HTTP message = standard, but to be middleware IO standard, which happens to be mostly = (but not only) an HTTP message." It's an accurate assessment.) > I wonder if there are any lessons to be learned there in terms of what = kinds of immutability the language should encourage / make easy. I think there are; I wrote about at least some of them here ... = https://paul-m-jones.com/post/2016/09/06/avoiding-quasi-immutable-objects-= in-php/ ... in which I conclude that, if you want to build a truly immutable = object in PHP, it appears the best approach is the following: - Default to using only scalars and nulls as properties. - Avoid streams as properties; if a property must be a stream, make sure = that it is read-only, and that its state is restored each time it is = used. - Avoid objects as properties; if a property must be an object, make = sure that object is itself immutable. - Especially avoid arrays as properties; use only with extreme caution = and care. - Implement __set() to disallow setting of undefined properties. - Possibly implement __unset() to warn that the object is immutable. I put those conclusions (and other resulting from that article) into an = implementation described here: http://paul-m-jones.com/post/2019/02/04/immutability-package-for-php/ > is it better to constrain entire objects to be immutable rather than = individual properties? I would say that the entire object ought to be immutable, for reasons = that are difficult for me to articulate. > And should there be restrictions on what you can declare as immutable, = since "immutable resource" is largely nonsensical? I think so, and I note some of those restrictions above. In particular, = the immutability package ValueObject further inspects arrays to restrict = their values to immutables as well. --=20 Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php