Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108725 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14408 invoked from network); 23 Feb 2020 10:22:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Feb 2020 10:22:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7418D1804DF for ; Sun, 23 Feb 2020 00:39:38 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f41.google.com (mail-yw1-f41.google.com [209.85.161.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 23 Feb 2020 00:39:38 -0800 (PST) Received: by mail-yw1-f41.google.com with SMTP id b186so3798316ywc.1 for ; Sun, 23 Feb 2020 00:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=LU2xyTHGnZx4iTuZES8+2wPoylRPPv13h8KyviEMqb4=; b=aIqWNEK2JOSIHqw/eLnx4tQStIJdMJdF9tW45ZiQhHTo8TcFyfxCLoSDEE1A8f9k9v 9tMT+DAA5x/fyLb2/8bIfZa+XjW/LsGi1qB32o1Qo8hdsQFTOtNfYXJdDKIkQ03Z5d2m PfceM8g0qQn0T0TEfkZQio+zBmNBdYQambJf9WxY1dh7bJjWBXs5wnKMSbIjR10V25dH 9E7zbxX6/4wLzUJkVv63LW7laA0MSK6tcBKzSFxYpQbKzREdrJkGtjGi3lAMyVEqsDy4 oi64OyfQxGymQnZYVq4G063QeaIGeEWuXBn2i1nA1wOoY/BfgY5i2AInDOUpvDtD1BGw aQfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=LU2xyTHGnZx4iTuZES8+2wPoylRPPv13h8KyviEMqb4=; b=KfDz/jyTUqo7af/KDo+N8O7IswHjbPCUiCwrZAcV02SiuXUE0qsT0k4Y2eWdNwjEhX O9ESFg/gjM3c4rJjvFl1HYlcNKr9NXZik284ytg7j1AwxcaDiYzZ2miUQcIa4ISnxRGC i8ML0NGJjVUiOD9D7Ayw0vKVbHj7DCYQ7Us4YuOH13Tkd0c0WDhb/I9lBOGVOLjWwk3x 24fdcpBNLTbRx4bzwI2uAbxcSPAxH6xcX68BB8sMEhCCY+4OGORWHEdcK9OqMnEoJdIW XfG9eaKxoVg7jN3CAIjbEaiullJaUqOcdVs3vFbSz345hRl9cMPR1CpIS9L9Ji2o7Lkm bl5Q== X-Gm-Message-State: APjAAAXDdyD2EiMrc8PrynvKuVVB8dfoGYscpAP6x+2Ip7F0Fx4BaQCr lDkfSXgJSztqfcqepF9k+8LcJgAxZZRYBQ== X-Google-Smtp-Source: APXvYqxJ1SDfSiZzydcm7B79HSk0vOLFnMQyAeiy3J0ddwdOSBbRn7SttXrydTqTUo9thjSRg9M/Rg== X-Received: by 2002:a81:75c3:: with SMTP id q186mr38829923ywc.6.1582447176480; Sun, 23 Feb 2020 00:39:36 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:4032:6b9e:6c2d:f784? ([2601:c0:c680:5cc0:4032:6b9e:6c2d:f784]) by smtp.gmail.com with ESMTPSA id 141sm3805470yws.54.2020.02.23.00.39.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Feb 2020 00:39:34 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> Date: Sun, 23 Feb 2020 03:39:33 -0500 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <452D962A-C588-4F04-B000-479EBEA9B9DB@newclarity.net> References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> To: Larry Garfield X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: mike@newclarity.net (Mike Schinkel) > On Feb 21, 2020, at 6:17 PM, Larry Garfield = wrote: > I'm totally on board for better value object support, so that's a good = motive for me. The question I have is whether this is really a good = stepping stone in that direction or if it would lead down a wrong path = and lock us into too much TIMTOWTDI (for the Perl fans in the room). So = let's think that through down that path. How would write-once = properties lead into properly immutable value objects? Or do they give = us that themselves? >=20 > The biggest challenge for immutable objects, IMO, is evolving them. = Eg, $result->withContentType(...) to use the PSR-7 example. Would we = expect people to do it with a method like that, or would there be some = other mechanism? If the properties are public, would we offer a more = syntactic way to modify them directly? >=20 > The with*() method style requires cloning the object. What happens to = the locked status of a set property if the object is cloned? Are they = then settable again, or do they come pre-locked? >=20 > Neither of those seem good, now that I think about it. If they come = pre-locked, then you really can't clone, change one property, and return = the new one (as is the standard practice now in that case). If they = don't come pre-locked, then the newly created object can have everything = on it changed, once, which creates a loophole. I'm not sure what the = right answer is here. >=20 > My other concern is a public property (the most likely use case) would = have to be set in the constructor. If it's not, then callers cannot = rely on it having been set yet if it's set lazily. And if code inside = the class tries to set it lazily, it may already have been set by some = external code (rightly or wrongly) and cause a failure. >=20 > How do we address that? There's absolutely use cases where setting = everything in the constructor ahead of time is what you'd do anyway, but = there are plenty where you wouldn't want to, either, which creates a = race condition for who sets it first, or tries to access it before it = gets set, etc. (This is where my repeated questions about lazy = initialization come from.) I have struggled to follow this RFC thread fully, so if I am getting = something out of context, please note that and I apologize in advance. However, it would see that rules for `write once` properties to support = lazy loading would be rather simple: 1. Write-once properties can only be updated once. 2. Write-once properties can only be updated within the class where they = are declared. 3. If you want to update a property from outside the class, create a = set_() method to allow it to happen. 4. If you do not want it to be set externally, do not implement a = set_() method. 5. If you want it to be implemented externally sometimes but not others, = implement guard classes inside the set_() method. I think that addresses all scenarios, no? -Mike=