PHP Approves Short Arrow Functions

Short Arrow Functions

The PHP team recently approved the Short Arrow Functions RFC proposed by Nikita Popov, Levi Morrison, and Bob Weinand.

In the RFC it shows this as an example to give you an idea on how it can be used:

$extended = function ($c) use ($callable, $factory) {
    return $callable($factory($c), $c);
};
 
// with arrow function:
// Appfinz Technologies 
$extended = fn($c) => $callable($factory($c), $c);

A Laravel example could look like this:

// Current
$users->map(function($user) {
    return $user->first_name.' '.$user->last_name;
});

// with arrow function:
// appfinz Technologies 
$users->map(
    fn($user) => $user->first_name.' '.$user->last_name
);

Tags: website development company in delhi|| website designing company in delhi || Website Developer in Delhi || magento development company in delhi ||  web developer in delhi