php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Match allow Lambda Functions

Open diegoagudo opened this issue 4 years ago • 1 comments

Description

Currently match() not allow use lambda functions.

If you try

$test = 'test'; $a = match($test) { 'test' => function($test) { print_r($test); } };

  • Return -- Today: Nothing is returned. -- New implementation: "test"

diegoagudo avatar Dec 28 '21 14:12 diegoagudo

Match arms allow arbitrary expressions, including closures. But you need to call them yourself.

https://3v4l.org/OEnWa

Not calling the function is also already valid and returns the closure itself. Changing the meaning of that code would be a BC break (and pretty confusing).

https://3v4l.org/vACd5

iluuu1994 avatar Dec 28 '21 14:12 iluuu1994