PHP Approves Short Arrow Functions

PHP Approves 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:
$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:
$users->map(
    fn($user) => $user->first_name.' '.$user->last_name
);

Short Arrow Functions is targeted for inclusion in PHP v7.4, and you can read more about this on the PHP wiki and listen to the PHP Internals Podcast where Nikita Popov joins them to discuss this change.


Filed in: News / php7.4


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Remote PHP / Laravel Developer
Remote
SpringboardVR
Senior PHP/Laravel Developer: Your Dream Work Environment
Remote
iPhone Photography School
Senior Laravel Developer
Leidseplein, Amsterdam
Orderchamp.com
PHP Developer
Remote
X-Team
Senior Laravel Developer (Canada and India)
London, Ontario, Canada
Factory Bucket Inc.
Laravel, PHP, PostgreSQL, Neo4J Developer
Pune, India (intern in Denver, CO)
Life AI
Senior Laravel Developer - Cloud based SaaS product (New Zealand based)
Auckland city
Figured Limited