Hello,

On Wed, Jun 1, 2011 at 2:17 PM, Anthony Ferrara <ircmax...@gmail.com> wrote:
> Personally, I think focusing on a character savings is the wrong
> reason to take on any problem.  I don't care how long it takes for me
> to type code.  I don't care how much extra hdd space it takes.  But
> what I do care about is how readable it is.
>
> To me, the array shortcut syntax is pointless.  Do you really mean to
> tell me that `[1, 2]` is more readable/easier to understand than
> `array(1,2)`?  To me, it's about a wash.
>
> However, the object shortcut syntax is a major win.  For example:
>
> $person = new stdClass();
> $person->city = 'ogden';
> $person->state = 'ut';
> $perspn->country = 'usa';
> $person->favoriteNumbers = array(4, 12, 37, 42);
> $person->somethingWithNumbers();
> $person->unluckyNumbers = array(6, 13, 21);
> $person->likesPhp = 'very much so';
>
> vs
>
> $person =  { 'name' => 'Justin',
>   'city' => 'ogden',
>   'state' => 'ut',
>   'country' => 'usa',
>   'favoriteNumbers' => [ 4, 12, 37, 42],
>   'unluckyNumbers' => [ 6, 13, 21],
>   'likesPhp' => 'very much so'
> }
>
> Did you notice what happened there?  There's two differences.  Try to
> find them.  Neither would be possible with the shortcut syntax.
>

I don't think doing this is a very big deal, even in the case of Array().
 $person = (object) [ 'name' => 'Justin',
   'city' => 'ogden',
   'state' => 'ut',
   'country' => 'usa',
   'favoriteNumbers' => [ 4, 12, 37, 42],
   'unluckyNumbers' => [ 6, 13, 21],
   'likesPhp' => 'very much so'
 ]

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

Reply via email to