Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108690 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60731 invoked from network); 19 Feb 2020 23:33:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Feb 2020 23:33:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B76B21804F6 for ; Wed, 19 Feb 2020 13:49:49 -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,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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, 19 Feb 2020 13:49:49 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6D23A22195 for ; Wed, 19 Feb 2020 16:49:48 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 19 Feb 2020 16:49:48 -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=fm2; bh=VAhXt+2G1FlCjVnc+oYOgOiO9gahb4boPk6ygslr3 Kg=; b=E6RkEprPNamo1aRd/RMIozqCPd/f4Q5tviREuk0N2TerjHSZJKy6iaEN2 xGqrt60xu7g24gu62fg7VU0OubwAQdkSSa2ds/P7LV8E+FFGKREutPe4gYrJNt40 5qEky0IEutjN6PHaAqyMGMS0FeECH0a4YkZ2O7+JrTP1jY3QZ4zyDGb+BKxzSRMx kKXPYddH2BxbEEpImtFDIvRFEMf3MmisrTyQ5s8T1HiP41jS7U8DVqj8zqcbhs7d aB1MPrAeKYoJ5dxs5OYPVhGelUgPWBc90OjdtiJyRucyY3nSB8AWcvezYzrz2Bp0 WSePd65KfeMXHLTNm2B+nY5/2TYnQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrkedtgdduheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 18C0714200A2; Wed, 19 Feb 2020 16:49:48 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-802-g7a41c81-fmstable-20200203v1 Mime-Version: 1.0 Message-ID: <75810945-7aa3-45a9-a2fa-eb71db695e9b@www.fastmail.com> In-Reply-To: References: <65c78b5a-55a6-4f1f-b881-f1401aa7dbb1@www.fastmail.com> Date: Wed, 19 Feb 2020 15:49:17 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: larry@garfieldtech.com ("Larry Garfield") On Wed, Feb 19, 2020, at 1:36 PM, Marco Pivetta wrote: > On Wed, Feb 19, 2020, 19:51 Larry Garfield wr= ote: >=20 > > On Wed, Feb 19, 2020, at 11:05 AM, M=C3=A1t=C3=A9 Kocsis wrote: > > > Hi Internals, > > > > > > I'd like to move my RFC forward to the discussion phase: > > > https://wiki.php.net/rfc/write_once_properties > > > > > > In short, I propose to add support for a new property modifier tha= t would > > > allow properties to be initialized, but not modified afterwards. > > > > > > Cheers, > > > M=C3=A1t=C3=A9 Kocsis > > > > As envisoned, does this allow for a property to be set to a dynamic > > value? My concern is that while a public locked/writeonce property = is > > great for access, it doesn't do anything to enable lazy setting on f= irst > > access. In fact the only way to do that would be to make it private= and > > wrap access in a method, which would look exactly like that does now= but > > with an extra keyword that doesn't actually offer much. > > > > You could set the value in advance in the constructor, but then it's= not > > lazy, just locked. > > > > Is there a way it could support lazy-on-first-use then locked? >=20 >=20 > M=C3=A1t=C3=A9 did run a few teats: operating on a lazy value (before = initialisation) > seems to work as expected =F0=9F=91=8D Erm. I don't think I was clear in my intent. I would expect that opera= ting on one of these properties before it's initialized will throw an er= ror: class Foo { readonly public string $bar; } $f =3D new Foo(); print $f->bar; // This should fail. My question is whether this will work: class Foo { readonly public string $bar =3D $this->value(); private function value(): string { return "hello"; } } $f =3D new Foo(); print $f->bar; // I would want this print "hello". Does that work currently or no? If so, this is pretty sweet. If not, i= t seems to be of limited use. --Larry Garfield