Re: Alias stdClass to DynamicObject?
| From: | Kamil Tekiela | Date: | Mon, 06 Sep 2021 16:49:59 +0000 |
| Subject: | Re: Alias stdClass to DynamicObject? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115970@lists.php.net to get a copy of this message | ||
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.
Regards,
Kamil