Functional approach in PHP

The code snippet below will only work in PHP-5.3+!. Isn’t it the famous functional programming with functions as first class citizens, closures and other functional bla-bla? <?php> function one($a = 0) { return function(callable $b) use ($a) { return call_user_func($b, $a); }; } print_r(call_user_func(one(1), function ($x) { return $x + 4; } )); This was created just for fun. As you may see, in place of callable you can put any valid PHP callable, e.g.in a form ['Class', 'method'] ...

October 19, 2016 · 1 min · rodush