1.2.1310. 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.1310.1. Specs

Short name

Functions/UseArrowFunctions

Rulesets

All, Appinfo, CE, Changed Behavior, One Liners

Exakat since

1.9.4

PHP Version

With PHP 7.4 and more recent

Severity

Time To Fix

Precision

Very high

Features

arrow-function

Available in

Entreprise Edition, Community Edition, Exakat Cloud