Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115803 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60719 invoked from network); 25 Aug 2021 10:18:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Aug 2021 10:18:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE06D1804B3 for ; Wed, 25 Aug 2021 03:52:23 -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.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS14061 82.196.0.0/20 X-Spam-Virus: No X-Envelope-From: Received: from mobilejoomla.com (mobilejoomla.com [82.196.7.134]) (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 03:52:23 -0700 (PDT) Received: from [192.168.88.251] (95-24-2-62.broadband.corbina.ru [95.24.2.62]) by mobilejoomla.com (Postfix) with ESMTPSA id D4F6C1DF0 for ; Wed, 25 Aug 2021 10:52:21 +0000 (UTC) To: PHP internals References: Message-ID: <2c275aa7-f22f-70aa-283c-f6d22b8490bc@mobilejoomla.com> Date: Wed, 25 Aug 2021 13:52:20 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: denis@mobilejoomla.com (Denis Ryabov) On 25.08.2021 13:02, Nikita Popov wrote: > Hi internals, > > 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 > > This has been discussed in various forms in the past, e.g. in > https://wiki.php.net/rfc/locked-classes as a class modifier and > https://wiki.php.net/rfc/namespace_scoped_declares / > https://github.com/nikic/php-rfcs/blob/language-evolution/rfcs/0000-language-evolution.md > as a declare directive. > > This RFC takes the more direct route of deprecating this functionality > entirely. I expect that this will have relatively little impact on modern > code (e.g. in Symfony I could fix the vast majority of deprecation warnings > with a three-line diff), but may have a big impact on legacy code that > doesn't declare properties at all. > > Regards, > Nikita I use dynamical properties in a legacy code for lazy object creation in the dependency container (with properties declared using @property phpDoc comment, so that PhpStorm IDE supports them). But in my case it's not a problem to refactor that code. I'd suggest to consider "use stdClassTrait" (the name is just for example) as an alternative to "extends stdClass" and "implements stdClassInterface", because 1) It allows to further implement __get/__set in that trait, and 2) It's possible to don't require base abstract class to extend stdClass when dynamical properties are used in a child class only.