On 06.09.21 17:28, Nikita Popov 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?
I do like the idea very much as "stdClass" is most confusion and also wrong.
The name "DynamicObject" is much better but I'm not sure if this is a
good name either.
* It's a class -> Why do we suffix it with "Object"?
* Yes it's about dynamic properties - but is this the user goal to have
dynamic properties or is it an implementation detail to get something
else (map/dict)?
Wouldn't it be better to name it for what purpose it's being used
(map/dict/ordered dict/...) instead of how this is done? And if we want
to go that route we could also add common functionalities to it like
getting list of keys/values converting to array iterating etc. it's
already possible right know by casting to array but it would be more
logically.
Yes we have assoc arrays in PHP to serve the purpose but this also has
it's downsides as there is no type for it and the issue of converting an
empty array from/to JSON (is it a list or a map?).
The big difference, of course, is the by-ref vs. by-value.
Hope that's not stupid questions?
Greetings,
Marc
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php