草庐IT

anonFunction

全部标签

php - 在php中调用定义为对象变量的匿名函数

这个问题在这里已经有了答案:Callingclosureassignedtoobjectpropertydirectly(12个答案)关闭9年前。我有这样的php代码:classFoo{public$anonFunction;publicfunction__construct(){$this->anonFunction=function(){echo"called";}}}$foo=newFoo();//Firstmethod$bar=$foo->anonFunction();$bar();//Secondmethodcall_user_func($foo->anonFunction)