Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard In PHP for Return Lines when Chaining Function Calls [closed]

I haven't been able to find an answer for this in any of my Google searches but is there a standard/best practice for return lines before or after the arrow operator when I chain function calls across lines?

The two options I've come up with are return after the arrow operator:

$myclass->
    foo->
    bar->
    baz();

And before the arrow operator:

$myclass
    ->foo
    ->bar
    ->baz();

We're trying to stick to PSR-2 coding standards if at all possible.

like image 777
Scott Keck-Warren Avatar asked Oct 04 '22 10:10

Scott Keck-Warren


1 Answers

PSR2 doesn't specify. See https://stackoverflow.com/a/11894206/2016155. Second option is more readable though if you ask me.

like image 195
Charles R. Portwood II Avatar answered Oct 10 '22 04:10

Charles R. Portwood II