Refactoring to arrow function In this refactoring we change a function call to fn, for onliners this is a huge improvement
requires: php 7.4.0

Arrow functions were introduced in PHP 7.4 as a more concise syntax for anonymous functions. Both anonymous functions and arrow functions are implemented using the Closure class. Arrow functions have the basic form fn (argument_list) => expr. Arrow functions support the same features as anonymous functions, except that using variables from the parent scope is always automatic. When a variable used in the expression is defined in the parent scope it will be implicitly captured by value. In the following example, the functions $fn1 and $fn2 behave the same way.

Original code

        $a 5;
$b 6;

$a $b;

$product multiply($a$b);


Refactored code

        $a 5;
$b 6;

$multiply = fn($a$b) => $a $b;
$product  $multiply($a$b);


Here is the output of the code

This is the output of original


This is the output of refactor


Want to learn more from LLoadout ?

LLoadout is your loadout for Laravel, helping you kickstart your development process. Besides this refactoring site we also make some cool packages and video tutorials !

Go to LLoadout on github