1.2.1320. Use Arrow Functions¶
Arrow functions are closures that require one expression of code. They also include all the variables of the current context, unless they are made static.
Arrow functions were introduced in PHP 7.4. They added the reserved keyword fn
.
<?php
array_map(fn(A $b): int => $b->c, $array);
function array_values_from_keys($arr, $keys) {
return array_map(fn($x) => $arr[$x], $keys);
}
?>
See also RFC : Arrow functions and Arrow functions in PHP.
1.2.1320.1. Connex PHP features¶
1.2.1320.1.1. Specs¶
Short name |
Functions/UseArrowFunctions |
Rulesets |
|
Exakat since |
1.9.4 |
PHP Version |
With PHP 7.4 and more recent |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |