PSR-2 section 4.6 with shorthand array

501 views
Skip to first unread message

Chuck Reeves

unread,
May 21, 2013, 9:47:46 AM5/21/13
to php...@googlegroups.com
I would like to get an opinion on this section when using array shorthand. IMHO an exception should be made if I am going to build the array into the function.

Consider the simple example for: $keys = array_values(['foo', 'bar', 'baz', 'bat']);  If I were to break this out across multiple lines, following the current spec I would have to do the following:

$keys = array_values(
    [
        'foo' => 'bar', 
        'baz' => 'bat'
    ]
);

Or:

$keys = array_values(
    ['foo' => 'bar', 
    'baz' => 'bat']
);

Or:

$keys = array_values(
    [
    'foo' => 'bar', 
    'baz' => 'bat'
    ]
);

All will pass the sniffer. 

IMHO I would like to be able to do the following:

$keys = array_values([
    'foo' => 'bar', 
    'baz' => 'bat'
]);

Keep the opening and closing brackets on the same line as the opening and closing parentheses.  Any thoughts on this manner? 

Paul Jones

unread,
May 21, 2013, 10:05:25 AM5/21/13
to php...@googlegroups.com

On May 21, 2013, at 8:47 AM, Chuck Reeves wrote:

> IMHO I would like to be able to do the following:
>
> $keys = array_values([
> 'foo' => 'bar',
> 'baz' => 'bat'
> ]);
>
> Keep the opening and closing brackets on the same line as the opening and closing parentheses. Any thoughts on this manner?

I don't see a problem with this. It's a single parameter, so the square brackets can go next to the parentheses; and the elements of the array can go on their own lines.



-- pmj

Pádraic Brady

unread,
May 21, 2013, 11:11:04 AM5/21/13
to php...@googlegroups.com
Same here... Should be fine.

Pádraic Brady
http://blog.astrumfutura.com
> --
> You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
> To post to this group, send email to php...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/4C61889C-1223-4E1F-91EA-6BE01E8333EE%40gmail.com?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages