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

This is only part of a thread. view whole thread
  115812
August 25, 2021 14:00 nikita.ppv@gmail.com (Nikita Popov)
On Wed, Aug 25, 2021 at 3:51 PM Rowan Tommins collins@gmail.com>
wrote:

> On 25/08/2021 13:45, Nikita Popov wrote: > > > We obviously need to keep support for dynamic properties on stdClass, > > and if we do so, I would expect that to apply to subclasses as well. > > Does that actually follow, though? Right now, there is no advantage to > extending stdClass, so no reason to expect existing code to do so, and > no reason for people doing so to expect it to affect behaviour. >
Isn't this a direct consequence of LSP? We can't just drop behavior when extending. Only way for this not to follow would be if we disallowed extending from stdClass entirely, which we presumably don't want to do.
> Second, I consider "extends stdClass" to be something of a last-ditch > > option. If you encounter a dynamic property deprecation warning, you > > should generally resolve it in some other way, and only fall back to > > "extends stdClass" as the final option. > > > That's a reasonable argument in terms of the multiple inheritance case. > > My concern about the name remains though: people already do get confused > by the name "stdClass", because it's not in any way "standard", and > tells you nothing about what it does. > > Reading "class Foo extends stdClass" gives the reader no clues what > magic behaviour is being inherited; "class Foo extends DynamicObject" > would be much more clear. Similarly, "$foo = new DynamicObject; > $foo->bar = 42;" is clearer than "$foo = new stdClass; $foo->bar = 42;" >
Yes, I can see the argument for aliasing stdClass to something more meaningful, even independently of this RFC. I'm not sure it will have a big impact for this use-case though, because using the new name would require polyfilling it, so I'd expect people would stick to the old name in the foreseeable future... Regards, Nikita
  115818
August 25, 2021 14:49 rowan.collins@gmail.com (Rowan Tommins)
On 25/08/2021 15:00, Nikita Popov wrote:
> I'm not sure it will have a big impact for this use-case though, > because using the new name would require polyfilling it, so I'd expect > people would stick to the old name in the foreseeable future...
Not necessarily - it depends what versions you need to support, and what your migration strategy is. Since it's just a deprecation notice initially, you could support 8.1 and 8.2 on the same code base with no changes at all - that's what deprecation notices are for, to give a lead time before changes are mandatory. Once the code base no longer needed to support 8.1, "extends DynamicObject" could be added. For many code bases, that will be long before the feature is actually removed - for a private project, maybe as soon as it's on 8.2 in production. Regards, -- Rowan Tommins [IMSoP]