Re: [PHP-DEV] [RFC] Deprecate dynamic properties

This is only part of a thread. view whole thread
August 25, 2021 10:52 (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): > > > > This has been discussed in various forms in the past, e.g. in > as a class modifier and > / > > 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.