PhpStorm 2019.2 Help

Code Inspection: Closure can be converted to arrow function

Reports the anonymous functions that can be transformed to short arrow functions. The support for short arrow functions is announced for PHP 7.4.

See PHP RFC: Arrow Functions 2.0 (php.net) for details.

In the following example, the callback anonymous function inside array_map is written in two forms: regular and arrow.

Regular form

Arrow function form

$myArr = [1, 2, 3, 4, 5, 6]; $doubledValues = array_map(function ($var) { return $var * 2; }, $myArr);
$myArr = [1, 2, 3, 4, 5, 6]; $doubledValues = array_map(fn ($var) => $var * 2, $myArr);
Last modified: 23 August 2019