Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

piljac1's avatar
Level 28

PSR standard for PHP arrow functions?

Hey guys! I was just wondering if there's any PSR standard regarding PHP arrow functions. In the PHP doc, the RFC and some articles they use the functionality as follows: fn() => 'value', but I haven't found anything PSR related that states a "SHOULD" or "MUST" usage.

I'm surprised that everything I see is fn() with no space between fn and the parentheses when PSR-12 states that (long form) closures should be written function () with a space between function and the parentheses.

Thanks in advance!

0 likes
2 replies
jlrdw's avatar

If there are none, I would probably go by the PHP manual and their examples.

Edit: found this in psr 12.

When space is permitted around an operator, multiple spaces MAY be used for readability purposes.

All operators not described here are left undefined.

piljac1's avatar
piljac1
OP
Best Answer
Level 28

Thanks for your input! I found fn ($invoice) => $invoice->submit() here in the Laravel doc, so I will consider that as the way to go moving forward, since I'm working in Laravel projects, except if a robust standard is implemented in the future.

1 like

Please or to participate in this conversation.