【发布时间】:2013-07-12 10:39:37
【问题描述】:
我试图从同一个类的另一个方法中的闭包内部调用一个类的私有静态方法,但我找不到正确的方法...... 即使使用 use 引用私有方法...我能够引用私有变量并传递它,但无法引用私有方法... $refMethod = array('App','_onEvent');与 call_user_func($refMethod) 将抛出该方法是私有的... 我也尝试使用 PHP 5.4 版本的 ReflectionClass (WAMP 32bits),但它说实例上不存在 getClosure 方法:(
class App(){
static public function start(){
new Form('myform', array('submit'=>function($form) use($someVar){
if($anyCondition){
// want to call private self::_onEvent here : any suggestion ?
}
}));
}
static private function _onEvent(){
// this is my very private part
}
}
好吧,我知道闭包没有范围,但是……任何传递私有上下文的方法(因为闭包在类内部)来完成这样的事情?谢谢你的灯!
编辑:我真的很想做this answer,但这只是抛出了伟大的
当没有类作用域处于活动状态时无法访问 self::
【问题讨论】: