Re: Alias stdClass to DynamicObject?
| From: | Larry Garfield | Date: | Tue, 07 Sep 2021 14:18:27 +0000 |
| Subject: | Re: Alias stdClass to DynamicObject? | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115995@lists.php.net to get a copy of this message | ||
On Tue, Sep 7, 2021, at 4:22 AM, Nikita Popov wrote:
> On Mon, Sep 6, 2021 at 6:50 PM Kamil Tekiela <tekiela246@gmail.com> wrote:
>
> > Hi Nikita,
> >
> > I think this might be a good idea, but I would like to propose yet another
> > variant.
> > Replace stdClass with DynamicObject and keep stdClass as an alias. It can
> > be deprecated in 8.3.
> > If we only add an alias, I am afraid that it will not catch on quickly
> > enough. What I am proposing is that the cast to object will create
> > DynamicObject by default.
> >
> > $arr = [1,2];
> > var_dump((object) $arr);
> > Output:
> > object(DynamicObject)#1 (2) {
> > ["0"]=>
> > int(1)
> > ["1"]=>
> > int(2)
> > }
> >
> > It will break unit tests and it might break some code (e.g. `if ('stdClass'
> > === $class)`), but it will help people understand what is the preferred
> > name going forward without deprecating it right now.
> >
>
> My only apprehension with making stdClass rather than DynamicObject the
> alias is the widespread impact this will have on extension testing code.
> https://github.com/php/php-src/pull/7475 shows the approximate
> impact on
> php-src. We need to update references to stdClass in var_dump() output in
> more than 300 tests. We can do this easily, but it will be an inconvenience
> for 3rd party extension tests that need to deal with more than one PHP
> version.
>
> Apart from that I agree that making DynamicObject the actual name and
> stdClass the alias would be better.
>
> Regards,
> Nikita
Adding the alias, I'm fully on board with.
Removing stdClass any time before PHP 10, I'm not on board with. The user space breakage
potential is too large to even be thinking about that at this point.
Flipping the alias around... again, I'm very concerned about the BC breakage. Apparently
readonly caused problems for Wordpress, which is doubleplusungood. I would assume that
we can't safely change which is the real name until proven otherwise, and based on
Nikita's comments about PHP's own tests, I'd say it's definitely not proven
otherwise.
--Larry Garfield