> On Sep 6, 2021, at 11:28 AM, Nikita Popov <nikita....@gmail.com> wrote:
> 
> Hi internals,
> 
> In the thread for deprecation of dynamic properties, Rowan suggested that
> we alias "stdClass" to "DynamicObject" in
> https://externals.io/message/115800#115802. I wanted to split this
> discussion off into a separate thread, as this can be decided independently.
> 
> The rationale for this is that "stdClass" is something of a misnomer: The
> name makes it sound like this is a common base class, as used in a number
> of other languages. However, PHP does not have a common base class. The
> only way in which "stdClass" is "standard" is that it is the return type of
> casting an array to (object).
> 
> The actual role of stdClass is to serve as a container for dynamic
> properties, thus the suggested DynamicObject name.
> 
> What do people think about adding such an alias? Is this worthwhile?

So I am trying to get around what this would actually mean in practice, and 
what the ramifications would be.

Given this proposal would `(object)array()` return an object of class 
'DynamicObject' instead of 'stdClass'?

Will I be able to do a `new DynamicObject` just like I can currently do `new 
stdClass`?  I assume that instance would have a class of 'DynamicObject'?

And what of `new stdClass`?  Would `get_class(new stdClass)==='DynamicObject'` 
or would it continue to be `get_class(new stdClass)==='stdClass'`

Or would this be just like any class we can define today but that would still 
support dynamic properties whereas all other classes would disallow dynamic 
properties per the other proposal?

What about standard library functions that return a `stdClass` object?  (I 
assume there has to be at least one but I am not certain there is.). Assuming 
there are standard functions that return objects, will they now return 
'DynamicObject' or still 'stdClass'?

===========

So while trying to get my head around the ramifications I prepared this bit of 
introspection, which is still missing some applicable tests I am sure:

https://3v4l.org/MDlOn#v8.0.10 <https://3v4l.org/MDlOn#v8.0.10>

===========

What I am struggling with here is to understand the vision for this change. Not 
that I find the change a bad idea — I do think it intimates a good direction — 
but at least as presented if feels like the vision for this may not have been 
fleshed out, or at least not fully communicated.

Maybe what I am looking for is a vision for what this change would mean for 
future PHP.  Is it just a special-cases that will cause as much confusion for 
developers trying to understand why there are too names for the same thing as 
it will help those who will better understand the new name, or is it more fully 
addressing the use-case for why people use dynamic objects?  

Maybe that's where we should start. I know there are some people who (I think) 
strongly argue that we should never use non-typed objects ever again but why do 
people use dynamic objects, still? This is a legitimate question, not a 
rhetorical, snide or sarcastic one. 

===========

So what are the use-cases where dynamic objects still make sense, and just as 
importantly what about those use-cases is still suboptimal besides just the 
class name? (I can think of a few, but want to hear from others before I 
explain mine.)

-Mike

Reply via email to