Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97356 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35025 invoked from network); 11 Dec 2016 19:59:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2016 19:59:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.28 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.28 out4-smtp.messagingengine.com Received: from [66.111.4.28] ([66.111.4.28:43807] helo=out4-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/C0-27518-930BD485 for ; Sun, 11 Dec 2016 14:59:53 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 57BF72085E for ; Sun, 11 Dec 2016 14:59:50 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Sun, 11 Dec 2016 14:59:50 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=cPszFRBBQ8rKUf rSP7wfyFjQLG8=; b=HuSIKJ24YYCjjJFMFTCyWH+CRlEIudQu3qauRx1e0c0dUL Oyvi0XgzTNQ2Kaw3tm/mqPnO+2GMg8K3er2/b5ehUi3MYXeKNEn56TtTYUEHhFkw O44tEkXMOVOUZD5+DpKGME4HB7CcG3hUxEzEJYluV+vxnLJ1J53IOK4CLFufk= X-ME-Sender: X-Sasl-enc: +/vsIEC892pG2Ohu2D6BmTaUS1f+TGIugWs3ci2TKF0r 1481486390 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 1B5AE24E16 for ; Sun, 11 Dec 2016 14:59:50 -0500 (EST) To: internals@lists.php.net References: Message-ID: <1807f949-81d3-f2c4-8706-0fdade3ea51d@garfieldtech.com> Date: Sun, 11 Dec 2016 13:59:49 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------F91AE378C74216A436933CBE" Subject: Re: [PHP-DEV][RFC][DISCUSSION] - Immutable classes and properties From: larry@garfieldtech.com (Larry Garfield) --------------F91AE378C74216A436933CBE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 12/11/2016 10:57 AM, Silvio Marijić wrote: > Hi, > > Discussion is open for following rfc https://wiki.php.net/rfc/immutability > > Cheers > Some grammar issues: "After object is constructor" => should be "After the object's constructor has run". " If immutable property contains object, to preserve immutability, object that is beeing assigned to immutable property must also immutable." => "If an immutable property contains an object, then in order to preserve immutability the object being assigned must be of an immutable class." The File class/resource example should note that the last line in it will create a fatal error, as the earlier examples do. It's not clear that the example is an invalid one. In a few places, "If immutable property..." should be "If an immutable property..." There's several places where articles (the, an, etc.) are missing. "Notice in above examples removing getters and setting properties to public is optional. They simply doesn't need to be protected anymore in fact that immutable class objects are deeply frozen with eceptions on write." => "Notice in the above examples that removing getters and setting properties to public are optional. They simply don't need to be protected given the fact that immutable class objects are frozen on write." (Several grammar fixes, plus it's a fatal error, not an exception.) Content issues: Currently the only "unlocked context" for an object is its constructor. As discussed previously, that is insufficient. For any non-trivial object (more than 1-3 internal properties) creating a new one via the constructor only when incrementally building is prohibitively difficult. The pattern of with*() methods that spawn new objects via clone(), a la PSR-7, needs to be supported. That is: immutable class Money { // ... public function add(Money $other) : Money { $new = clone($this); $new->amount += $other->amount; return $new; } } I'm not sure how easily we can denote that sort of case. It's outside the __clone() function itself, which is what makes it difficult. Without that, though, such immutable objects are of only limited use. --Larry Garfield --------------F91AE378C74216A436933CBE--