Re: RFC: Short syntax for Arrays (redux)
| From: | Justin Carmony | Date: | Tue, 31 May 2011 22:09:25 +0000 |
| Subject: | Re: RFC: Short syntax for Arrays (redux) | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-52603@lists.php.net to get a copy of this message | ||
I agree with this. So the idea would be adding short hand object notation for PHP, inspired by JSON,
but we also allow for associative arrays. So:
$object = { 'var1': 'one', 'var2': 'two' }; // for an object
$assoc_array = [ 'var1': 'one', 'var2': 'two' ]; // for an
array
// even mix and match
$person = {
'name': 'Justin',
'city': 'Ogden'
'phones' : [
'home': '555-3928',
'work': '555-3922'
]
};
echo $person->phones['home']; // output: 555-3928
The other option is the [] shorthand would create an ArrayObject, so you can interact with the
object like an array or object. But I think it is important that we make it possible to allow for
array AND object shorthand.
Justin
On May 31, 2011, at 3:56 PM, dukeofgaming wrote:
> Guys, as I said earlier, not even javascript (from javascript object
> notation, as in JSON) is 100% interoperable with JSON because single quotes
> are valid in javascript and not in json. I say ":" is way more cleaner than
> "=>" and it is a good opportunity to adopt it.