>I would prefer an improved syntax for creation of anonymous objects. This
>is something which I have been annoyed with, myself.I'd like to see a
>simple way of creating anonymous objects with typed properties.

Another advantage arrays currently have over anonymous objects is destructuring 
-
if this was (somehow?) also made possible with objects, this would be the
best of both worlds.
(Returning multiple named values from a function is also mentioned in the
use-cases of the RFC.)
I know this works:
```
[ "foo" => $foo, "baz" => $baz ] = (array) $object;
```
(Alternatively also using get_object_vars() instead of casting.)
But we both have to convert to an intermediate array again, and lose the
type information of the object (eg. for static analysis), so this could also be
made more ergonomic if we want to go down the anonymous object route.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to