# Arrow functions in PHP 7.4 PHP 7.4 is on RC2 version now and hopefully will be released in about 2 months. List of new features are [here](https://www.php.net/manual/en/migration74.new-features.php) (this page can actually be updated when 7.4 is released). In 7.4, finally PHP has got the arrow functions, so not only function answers can be shorter now, but also passing closures to other functions can be a lot shorter too. Here are a few examples: **Return input + 1:** Anonymous function (closure) - 25 bytes - [Try it online!](https://tio.run/##K8go@G9jX5BRwMWlkmb7P600L7kkMz9PQyVPs7ootaS0KE8lT9vQuva/NRdXanJGvoJKmoaRpvV/AA "PHP – Try It Online") <!-- language-all: lang-php --> function($n){return$n+1;} Arrow function - 12 bytes - [Try it online!](https://tio.run/##K8go@G9jX5BRwMWlkmb7Py1PQyVP09ZOJU/b8L81F1dqcka@gkqahpGm9X8A "PHP – Try It Online") <!-- language-all: lang-php --> fn($n)=>$n+1 **Multiply items of first input (array of ints) by second input (int):** Anonymous function (closure) - 72 bytes - [Try it online!](https://tio.run/##RcqxDoJADADQ/b6CoUNruojAcho/xBhSCBcYrE29G4zh28@RNz9brV7vtloIkG41FZ3z9lYEYVD6@ZKLayPu8h1fYniEicpnwSPBdAKNO4NQ3GsMwXzTPDpCwseZW75wxz0PT25aolj/ "PHP – Try It Online") <!-- language-all: lang-php --> function($a,$n){return array_map(function($b)use($n){return$b*$n;},$a);} Arrow function - 38 bytes - [Try it online!](https://tio.run/##Fcg7DoAgDADQnVM4dADTRfwsih7EGFIGgoNNQ1w8fdU3PimiyyZFjIEcNLMFQmAXVqqVnniR2D/TN5BaYARyOhsj9eQ7VgvZ7h167HHAEacDG@/crC8 "PHP – Try It Online") <!-- language-all: lang-php --> fn($a,$n)=>array_map(fn($b)=>$b*$n,$a) Did you notice that `$n` is accessible in the inner function without a `use $n` statement? Yeah that is one of the arrow function features. ----- As a side note, I could not get arrow functions to work recursively (call the same arrow function inside itself), because we cannot give them a name and storing them as a closure in a variable like `$f` doesn't make `$f` accessible withing itself (sad). So this example **doesn't work** and using `$f` in first line causes a fatal error: <!-- language-all: lang-php --> $f=fn($n)=>$n?$f($n-1):0; $f(5); // Causes error: "PHP Notice: Undefined variable: f" + "PHP Fatal error: Uncaught Error: Function name must be a string" But calling an arrow function withing a different arrow function works: <!-- language-all: lang-php --> $f1=fn($n)=>$n+1; $f2=fn($n)=>$f1($n-1); $f1(2) // Returns 3 $f2(2) // Returns 2