How do you write PHP Arrow function with multiple line expressions? JavaScript One Line Example: const dob = (age) => 2021 – age; PHP One Line Equivalent: $dob = fn($age) => 2021 – $age; …
Tag: arrow-functions
Use variable by reference in arrow function
PHP 7.4 introduced Arrow functions. And it also introduced implicit by-value scope binding which eliminate the need for use keyword. Now if we want to use a variable out of a closure’s scope by …
Rewriting an anonymous function in php 7.4
There is the following anonymous recursive function: I try to rewrite to version 7.4, but there is an error, please tell me what I’m missing? Notice: Undefined variable: f Fatal error: Uncaught Error: Function name must be a string Answer Just like Barmar said, you can’t use $f from the outside scope, because when the implicit binding takes place $f