How do I immediately execute an anonymous function in PHP?

前端 未结 9 1018
离开以前
离开以前 2020-11-27 03:29

In JavaScript, you can define anonymous functions that are executed immediately:

(function () { /* do something */ })()

Can you do somethin

9条回答
  •  星月不相逢
    2020-11-27 03:47

    For PHP7: see Yasuo Ohgaki's answer: (function() {echo 'Hi';})();

    For previous versions: the only way to execute them immediately I can think of is

    call_user_func(function() { echo 'executed'; });
    

提交回复
热议问题