// is this allowed or is it a personal preference?
SomeClass::someMethod([
'arg1' => 111,
], [
'arg2' => SomeClass::someMethod([
'arg5' => 999
]),
], [
'arg3' => [
'arg4' => 'zzz'
]
]);
//
// vs all array notations must be in new line
//
SomeClass::someMethod( [ 'arg1' => 111, ], [ 'arg2' => SomeClass::someMethod(
[
'arg5' => 999
]
), ], [ 'arg3' => [ 'arg4' => 'zzz' ], ]);
Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
SomeClass::someMethod(
// also, 4-space indents ;)
['arg1' => 111],
// Okay, but in my opinion starts to risk readability.
['arg2' => SomeClass::someMethod(['arg5' => 999])]
['arg3' => ['arg4' => 'zzz']]
);
A single argument being split across multiple lines (as might be the case with an anonymous function or array) does not constitute splitting the argument list itself.
somefunction($foo, $bar, [
// ...
], $baz);
However, the rule you're referencing is for when you are keeping arguments on the *same* line. It permits for splitting an array in that signature to multiple lines, and continuing the signature after the end of the multi-line array.
i see now your first example was following the guideline of the format from your second message. Your right, technically that does comply with the standard. When you start the signature on the same line as the opening "(", all successive arguments after should continue on the line where the previous argument ends. But hopefully you can see how muddled that pattern is for readability. It's hard to tell where the arrays begin or end, particularly in context of being function arguments. So many commas and brackets...
Honestly, i dislike the standard's allowance of the style in your second message. It seems very awkward and visually clunky to me. But i don't have a vote in accepting the standard, and came to the group a bit late to make a case for changing it. For me (and the guide my team uses), any time any argument is split to multiple lines, the whole signature should follow the multi-line signature rule.
Ultimately, i think the goal is readable & maintainable code, so when two versions are technically legal, let that objective be the deciding factor.
Hope that helps.
-jlt
A single argument being split across multiple lines (as might be the case with an anonymous function or array) does not constitute splitting the argument list itself.
somefunction($foo, $bar, [
// ...
], $baz);
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello ' . $app->escape($name);
});
someFunction(
$foo,
$bar,
['short', 'array', 'arg'],
$baz
);
//or
someFunction(
$foo,
$bar,
[
'longer' => 'array',
'with' => 'keys',
'or',
'other',
'mixed up stuff',
],
$baz
);
+1
Zitat von Joe T. <thoo...@gmail.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/2083e29f-f66e-4769-a6fb-f6b9dc710586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.