Anonymous functions with return as the only statement must use arrow functions.
Risky when using isset()
on outside variables that are not imported with
use ()
.
--- Original
+++ New
<?php
-foo(function ($a) use ($b) {
- return $a + $b;
-});
+foo(fn ($a) => $a + $b);
The rule is part of the following rule sets:
- Fixer class: PhpCsFixer\Fixer\FunctionNotation\UseArrowFunctionsFixer
- Test class: PhpCsFixer\Tests\Fixer\FunctionNotation\UseArrowFunctionsFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.