Creating and invoking an anonymous function in a single statement

前端 未结 4 1935
旧巷少年郎
旧巷少年郎 2020-12-09 10:03

A php closure or anonymous function is used to create function without specifying its name.

Is it possible to call them without assigning to identifier as we do in J

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 11:02

    PHP 7 added the ability to do this.

    This code:

    (function() { echo "This works as expected in PHP 7.\n"; })();
    

    works as one would expect in PHP 7. (It still doesn't work in any PHP 5.x. release)

提交回复
热议问题