Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115820 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98690 invoked from network); 25 Aug 2021 15:31:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Aug 2021 15:31:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2879E1804BD for ; Wed, 25 Aug 2021 09:05:28 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.0.0/20 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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, 25 Aug 2021 09:05:27 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 089DF5C00CD for ; Wed, 25 Aug 2021 12:05:27 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Wed, 25 Aug 2021 12:05:27 -0400 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=fm3; bh=JDqdq/iMZPk05d+l8lyHV6/GjNKr77y6MDymv8Sfj 8w=; b=fOWCpESStzuo/iP1AojkZkbQXiN0n4HnaQKKcR5acqxtFyRlinwdaAfEz WAy5VOpssu/rvIdgaVFTwSnSWQ3VcRkAuwSV2Kkh6IAoLXlkkvPrwAZvocirhp68 qrVBBP+TfsUjQtNxgEFSHOqVAWvpa+ULuLq81L50xCM+K6FfJPEfPp1kIBGQeSsE AY2zknmFK2s5nc3oPI6vcUzV15jHNaDJzjJTFuptXSguPtk9KTfbMGPilwQk0q23 ySM5Z9wnteybUqWrHiItm3YTJ7A4WfJ0ReO1ZGIGLivqhnGhFGAAKDFRQVcxp51j 3GWhZn1vtmwmARrI9tZxvmXIPSUww== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddtledgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeeghefgteejheeggfeghfelueeggfdtjeeivedv tefhveeguedufeelhedvteeinecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 734D1AC0DD1; Wed, 25 Aug 2021 12:05:26 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1125-g685cec594c-fm-20210825.001-g685cec59 Mime-Version: 1.0 Message-ID: <2c6adf5e-3ebb-4179-b654-de91f33c06f7@www.fastmail.com> In-Reply-To: References: Date: Wed, 25 Aug 2021 11:05:05 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: larry@garfieldtech.com ("Larry Garfield") On Wed, Aug 25, 2021, at 10:28 AM, Sara Golemon wrote: > On Wed, Aug 25, 2021 at 5:03 AM Nikita Popov wr= ote: > > I'd like to propose the deprecation of "dynamic properties", that is > > properties that have not been declared in the class (stdClass and > > __get/__set excluded, of course): > > > > https://wiki.php.net/rfc/deprecate_dynamic_properties > > >=20 > > This RFC offers `extends stdClass` as a way to opt-in to the use of > dynamic properties. > > > This makes the assumption that existing uses of dynamic properties are= all > root classes. I don't think that assumption can be made. >=20 > > Some people have suggested that we could use a magic marker > > interface (implements SupportsDynamicProperties), > > an attribute (#[SupportsDynamicProperties]) > > or a trait (use DynamicProperties;) instead. > > > My gut-check says an Attribute works well enough. This will unlock the > class (disable deprecation warning) in 8.2+ and be ignored in earlier > releases (8.0 and 8.1 would need an auto-loaded polyfill userspace > attribute obviously, but that's a tractable problem). >=20 > #[SupportsDynamicProperties] > class Foo { ... } >=20 > > The Locked classes RFC took an alternative approach to this problem = space: > > Rather than deprecating/removing dynamic properties and providing an > opt-in > > for specific classes, it instead allowed marking specific classes as > locked in > > order to forbid creation of dynamic properties on them. > > > > I don't believe that this is the right strategy, because in contempo= rary > code, > > classes being =E2=80=9Clocked=E2=80=9D is the default state, while c= lasses that require > dynamic > > properties are a rare exception. Additionally, this requires that cl= ass > owners > > (which may be 3rd party packages) consistently add the =E2=80=9Clock= ed=E2=80=9D keyword > > to be effective. > > > I struggle here, because the opt-in approach is the most BC, but I act= ually > think you're right. I think[citation needed] that dynamic props are > probably rare enough that as long as the escape hatch is clear, we can= be a > little more bold about nudging the ecosystem forward. I will counter > however, that the same issue with 3rd party libraries applies to opt-o= ut as > opt-in. A third party library that's undermaintained (and uses dynamic > props) won't be able to be used out of the box once we apply this. I = don't > think that's enough to scare us off, it just means that the opt-in sid= e of > that argument cancels out. >=20 > -Sara I am overall in favor of this move and making declared-only the default.= What I'm still undecided on is what escape hatch should be allowed. I= agree that "you can extend stdClass already" isn't a good one, because = that isn't viable in many cases. The most viable options in my mind are "use __get/__set yourself, you he= athen" and an attribute. The benefit of an attribute over an interface = or new parent class is that it's silently backward compatible, especiall= y since attributes are comments in <8.0 versions, so legacy code can add= that marker and still be compatible with anything from 5.0 on. The "internal impact" section makes me lean toward the "__get/__set" opt= ion, but I don't fully understand the benefits of the impact. It seems = it would make the engine a little tidier and more efficient, but I don't= have a good sense for how much more efficient, which would need to be b= alanced against how much more INefficient user-space code with dynamic p= roperties would become. (Either using __get/__set itself, or inheriting= from a future stdClass that implements them internally.) IMO we should= prioritize engine efficiency over edge-case efficiency (which dynamic p= roperties are these days), but the amount still matters. I'm currently working on some improvements to the FIG to allow it to rel= ease small, incomplete code libraries or shared type libraries. Perhaps= a fully user-space BC trait with the basic behavior (basically what's s= hown in the RFC) could live there? (Not speaking on FIG's behalf, here,= just musing aloud.) --Larry Garfield