Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115229 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6847 invoked from network); 30 Jun 2021 09:01:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jun 2021 09:01:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 52F76180501 for ; Wed, 30 Jun 2021 02:21:34 -0700 (PDT) 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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.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 ; Wed, 30 Jun 2021 02:21:33 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id u13so3889487lfk.2 for ; Wed, 30 Jun 2021 02:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8gtUiM6w/ePHAj48oMr7Zv5QZpHz2MSe9QNWXkuWhy8=; b=r5kR4pMATjZK0cYtaPs5mtAamccobtKyyGmvC2VNwZETUtJo10vVHrhfJCT97fRtWT iMKyJexnTnUTCDeYSoGg3Ms6X53U5BvUQ3baOE2S1463kW/r1rzb9bH8w1vfOX4HzYlT EiOnPWsF0qxcgeusVi+NdWPeeAue35vz+sHLuWLmKKk9p8v2IZcw7GKIskL2iQmlNHAa bCqW3VnzUcLd+c4TOppI8E9IReLu6tUyCCG9FXJqPW5b9z6oW9d0ccBjQjzQ3tp+dVsN 1W8yo/OLlIZApaS8cD/GA1v1n8S/+1vyDZLb/2P25ZEIs+LWZ/xfUFlDyEDUs5dBvp1C JFaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8gtUiM6w/ePHAj48oMr7Zv5QZpHz2MSe9QNWXkuWhy8=; b=hke7twFnavR4D1S8c3l4YA+0YYo7SEYOugMe2HQwCzbPaLbce7ZOvJuLu46SVHXkgi 2Q9nmWRcwvtQzH1PTSMAJq4RTV8TkYjF/+Zg+w6R1AH6UyzeuO0I7c2ljEhYOeBlXOmj MPFLWyGQCx4193xEN/1NAsc+o0Ro+T9osgh0svnKk59M/WZ3bVL9pRE1dPu6SDgAxVSL 9eB7X1O92WBfrPUY+HG/PxArXBylLZehjzogFeN/O+ztXImPSNg0QkIuIjsPU1k+1BGy x+ZjicoXTTJRIQB1lYSJead2+emMtFmAl3+rY558TdzADmteRvA/pq9FsETlYVmhJO/F FPpg== X-Gm-Message-State: AOAM532LI4N0ACbfxOFGDqqb4UQAh+npRO07eEhb8Pw/6rc9ykRqeFVN UbEqxV188NSAr/L8EOhkn9CrRLxjtfYacRjX5Rg= X-Google-Smtp-Source: ABdhPJxe+yczKgePBARJvysahvO1MjzbOEjLCxOyEN65i0pPc5KaC4lMQl6QGbFPP5/+ISmcnIUQ2NuLqQq+Sf+USQI= X-Received: by 2002:a05:6512:3d1d:: with SMTP id d29mr21311270lfv.286.1625044887864; Wed, 30 Jun 2021 02:21:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 30 Jun 2021 11:21:11 +0200 Message-ID: To: =?UTF-8?B?QW5kcsOpIFLDuG1ja2U=?= Cc: Larry Garfield , PHP Internals List Content-Type: multipart/alternative; boundary="00000000000049093205c5f83fe7" Subject: Re: [PHP-DEV] Re: [RFC] Readonly properties From: nikita.ppv@gmail.com (Nikita Popov) --00000000000049093205c5f83fe7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 30, 2021 at 10:36 AM Andr=C3=A9 R=C3=B8mcke wrote: > > > It's okay to vote against this if cloning is a deal breaker. In that > case > > > I'll probably either work on cloning before re-proposing this, or > pivot to > > > asymmetric visibility -- it's not my first preference, but it may be > the > > > more pragmatic choice. Cloning is definitely the weak point of this > > > proposal. > > > > I already went through the clone-arguments mental exercise in my earlie= r > analysis, and the code > > it produces is totally disgusting. :-) clone-with is a considerably > better approach if you're starting > > from readonly. (It's also better if you start from asymmetric > visibility, although that version needs > > a clone-help feature far less.) > > > Internals have been here before, it's a recurring problem in PHP that > fundamentally missing features are voted down because people want > other complementary features first. > > read only has been voted down by people rather wanting type properties > first, or rather wanted assessors first. And then in turn accessors > multiple times were voted down by the other 2 camps. But these > features are interconnected and need to be done step by step, during > the process things won't be perfect either way, > > Now we have read only vs clone with vs accessors vs ... > > IMO problem caused by no clear roadmap / vision of the project that > people can be united behind. > > -- > > Anyway, even though I tried to push for asymmetric visibility last > year I'd gladly vote +1 on this. > It's not perfect, but it's the right direction, and there are multiple > starting points to get there. > > This solves 80-90% of the use cases out there for read only > properties, which is a very good start. > > -- > > Nikita: Probably a small thing, but the only detail I'm unsure of is > why focus on write-once logic? Why not aim for aligning it with a > future *:init visibility, where I would think the property in PHP > should be writable in __construct(), __destruct() and __clone(). > > This won't solve the separate clone with feature request. But it would > make it more flexible and language design wise would set it up for > possible asymmetric visibility + init option later. > > For now it would at least allow setting default values on the > property, for instance if argument to constructor is not 1 to 1 with > property type/value and needs some light logic in __construct to > determine if property should be set to something else then default. > > But again, don't see a blocker here in current RFC, as it starts out > with a narrow scope of read only, and this can be widened later. Yes, this is a possible alternative interpretation of the readonly concept. The current proposal is closer to how Java final variables work, which never allow reassignment, while your suggestion is closer to C# readonly, which does allow reassigning in the constructor. I went with the current proposal, because it integrates nicely with the initialization concept introduced by typed properties. At the time, we also had lots of discussions about how typed property initialization should work, and requiring that all typed properties be initialized by the end of the constructor was one of the contenders. However, we ultimately decided against such an approach, because it does not integrate well with other aspects of the language. In particular we need to have the ability to initialize an object while bypassing the constructor, and we don't have the ability to determine initialization statically, so an uninitialized state would have been required in any case. If we had gone with that alternative initialization model at the time, then we would also use the same one for readonly properties. But that's not how things work now. Doing something like this now would require introducing an entirely new scoping concept. This brings up awkward questions like: How do you bind a closure to this new "initialization scope"? Closure rebinding is a common way to bypass visibility restrictions. What happens if you want to call a helper method to do the initialization, does that still count as initialization scope? What if you call $object->__construct() directly, will that allow changing properties? The current proposal tries to provide a simple, absolute guarantee: Once initialized, the property will never change again. I think that makes the feature easy to understand and reason about. Regards, Nikita --00000000000049093205c5f83fe7--