如何调用类的回调方法? [英] How to call callback method for class?
本文介绍了如何调用类的回调方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我
class xam{
public static function __callStatic($name, $arguments) {
self::$name();
}
static protected function mycallback(){
echo 'mycallback';
}
}
function doIt($callback) { $callback(); }
我正在尝试:
doIt(xam::mycallback);
错误:
致命错误:未定义的类常量'mycallback'
我知道一个变体:
doIt(function(){xam::mycallback();});
但是它可能还有其他选择吗? 感谢您的帮助.
But it may have an alternative ? Thanks for your help .
推荐答案
您可以将回调指定为字符串"xam::mycallback"
或数组['xam', 'mycallback']
. 手册描述了用于指定可调用对象的所有选项.
You can specify the callback as the string "xam::mycallback"
or array ['xam', 'mycallback']
. The manual describes all the options for specifying callables.
这篇关于如何调用类的回调方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文