Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:116477
Return-Path: <larry@garfieldtech.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 5526 invoked from network); 22 Nov 2021 16:56:02 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 22 Nov 2021 16:56:02 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id DA1881804B0
	for <internals@lists.php.net>; Mon, 22 Nov 2021 09:52:31 -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,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE
	autolearn=no autolearn_force=no version=3.4.2
X-Spam-ASN: AS19151 66.111.4.0/24
X-Spam-Virus: No
X-Envelope-From: <larry@garfieldtech.com>
Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29])
	(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 <internals@lists.php.net>; Mon, 22 Nov 2021 09:52:31 -0800 (PST)
Received: from compute6.internal (compute6.nyi.internal [10.202.2.46])
	by mailout.nyi.internal (Postfix) with ESMTP id A938A5C0273
	for <internals@lists.php.net>; Mon, 22 Nov 2021 12:52:30 -0500 (EST)
Received: from imap43 ([10.202.2.93])
  by compute6.internal (MEProxy); Mon, 22 Nov 2021 12:52:30 -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=fm1; bh=PT1qGcfnvk56aoHQFaCzkBaD5WaMmQ5UbY+3qyTyd
	K8=; b=Y6Q0ueG0+ApWAVUBREXiHmpezcrbPOMosU1L+lhVO/jLdc97gjsh5aAZC
	fIW+mf23jfddyrQFep1omHJc9QBDi9ireAhF25mRgGPnotZH1H+DD8J79onj/AFQ
	IhEq2i0ABWBI/lT6ItEThjsM31HLJt+30M52TtzhTFFnnpMS/URSOYxydU54UEyo
	G+sd+H85HaQseLBGztxyeNHgzS4yWSlNIEUlTFQ47r8D4FWFHyWkgPqaPRhvrAe1
	M5Fq0TDJlX0bgrLfTzJ/q2ap+2tus/WmUgKKrNsx9mPFT9mZ6nLtA+kGxJTm4zWG
	etz5HLzEZVklPr/kGaKYwFhrVLXSg==
X-ME-Sender: <xms:3tibYfpN3pwMcDIk_6Itpj_aEDQ7r9MFjtUHAVfqE0_iirVgJ9EdAQ>
    <xme:3tibYZrrI3s0x4AVazqIyaQMO9fGA61E_AXpzLOPM8vucp5uF3NJZD8Bft0-c-Aeg
    FBkCA7TqW-IKg>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrgeeggddutdejucetufdoteggodetrfdotf
    fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
    uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
    cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr
    rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg
    homheqnecuggftrfgrthhtvghrnhepgeeghefgteejheeggfeghfelueeggfdtjeeivedv
    tefhveeguedufeelhedvteeinecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth
    gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf
    ihgvlhguthgvtghhrdgtohhm
X-ME-Proxy: <xmx:3tibYcMEUGmFc3GFJ7Ab6c9wJykYgfRDprGP8b2yz_XlpUYf1GJg6Q>
    <xmx:3tibYS6lAH49jBNeZVHS9noiWNohpeZZW7wel729OOR3mL3JIhS14g>
    <xmx:3tibYe5sWaGhUpPmlFxDGN3-QXsAnzvAzha416ZAi0e9mNVo440p9Q>
    <xmx:3tibYdK0a2ynPReTIEIVpP4i0uLor4fpDGoJmTviw4FtueU3PFsLpg>
Received: by mailuser.nyi.internal (Postfix, from userid 501)
	id 7B7B0AC03DB; Mon, 22 Nov 2021 12:52:30 -0500 (EST)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.5.0-alpha0-1371-g2296cc3491-fm-20211109.003-g2296cc34
Mime-Version: 1.0
Message-ID: <4c685dfa-2a81-4eed-af70-3e34b7de50f0@www.fastmail.com>
In-Reply-To: 
 <CAH5C8xUn9fD5=hkKQL+CMWSMXEugpX=HbSRcWQ3WTksCpXdt_A@mail.gmail.com>
References: 
 <CAH5C8xUn9fD5=hkKQL+CMWSMXEugpX=HbSRcWQ3WTksCpXdt_A@mail.gmail.com>
Date: Mon, 22 Nov 2021 11:52:10 -0600
To: "php internals" <internals@lists.php.net>
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: quoted-printable
Subject: Re: [PHP-DEV] [RFC] [Discussion] Readonly Classes
From: larry@garfieldtech.com ("Larry Garfield")

On Mon, Nov 22, 2021, at 10:13 AM, M=C3=A1t=C3=A9 Kocsis wrote:
> Hi Internals,
>
> I'd like to propose adding support for readonly classes:
> https://wiki.php.net/rfc/readonly_classes
>
> The implementation heavily builds on the semantics of the already acce=
pted
> readonly properties RFC (https://wiki.php.net/rfc/readonly_properties_=
v2),
> basically the only thing I had to implement in the PR are the followin=
g:
> - Any declared property of a readonly class is implicitly treated as
> readonly
> - Creation of dynamic properties is forbidden
>
> Readonly classes would make it easier to declare immutable(-alike) cla=
sses,
> especially if a class
> contains a lot of properties. As a side-effect, one could already opt =
out
> from dynamic properties
> completely, which won't really be possible for quite some time, even if
> https://wiki.php.net/rfc/deprecate_dynamic_properties passes.
>
> Regards:
> M=C3=A1t=C3=A9

If I'm following, then this RFC is about 90% syntactic sugar for putting=
 `readonly` on all properties, plus disabling dynamic properties.  That'=
s the long-and-short of it, yes?

Does disabling dynamic properties offer any other advantages as have bee=
n discussed otherwise recently?  (E.g., performance.)

Is there a way to opt a given property back OUT of being readonly, or if=
 you have a readonly class and need to add a single mutable property to =
it are you stuck adding `readonly` to all existing properties first?  (I=
'm not sure I'm suggesting having such a mechanism, mostly just clarifyi=
ng.)

It's interesting that this also provides a backdoor way to force all pro=
perties to be typed, as a side effect.  However... that also means you c=
annot mark a class readonly if any of its properties are callables, sinc=
e callables cannot be typed. (I guess you could use mixed and then docbl=
ock callable, which is a bit fugly but not a problem introduced by this =
RFC.)

--Larry Garfield