3 ms·
There has been support for object literals for quite some time now (https://wiki.php.net/rfc/objectarrayliterals https://wiki.php.net/rfc/objectarrayliterals) b
by yogo 14y ago
There has been support for object literals for quite some time now (https://wiki.php.net/rfc/objectarrayliterals https://wiki.php.net/rfc/objectarrayliterals) but maybe just not enough. It would definitely be a welcome addition to the language. At least we no longer need to write array() for arrays lol.
- Mahn 14y agoOnly array literals were implemented though, not objects. That was long overdue, but in the age of JSON we live in it's not enough. For instance, the following in Javascript: var myObject = { memberOne: 'some string value', memberTwo: { subMemberOne: 42, subMemberTwo: 48 }, memberThree: false }; Has this as the closest equivalent in PHP right now: $myObject = (object) [ "memberOne" => 'some string value', "memberTwo" => (object) [ "subMemberOne": 42, "subMemberTwo": 48 ], "memberThree" => false ]; It's verbose, really, I would very much prefer a native solution that doesn't enforce casting from array and quotation around property names.
- yogo 14y agoI know, note what I said "...maybe just not enough. It would definitely be a welcome addition to the language" People have proposed it and commented on it but it does not get enough support (votes) from senior devs to get included. Maybe with more requests it will get included finally.