我正在使用匿名函数,我在对象外创建一个匿名函数,然后稍后将其添加到对象中,在其中使用__callStatic魔术函数。被添加的闭包包含来自父类的方法。我想知道是否能够从闭包中调用这些方法?
目前我得到了这个错误:
EmptyObject::addMethod('open', function(){
if (static::_hasAdapter(get_class(), __FUNCTION__))
return self::_callAdapter(get_class(), __FUNCTION__, $details);
echo '<p>You have mail!</p>';
});
抛出此错误:
致命错误:在没有类范围活动时无法访问 static::
以及
//Add the functions
EmptyObject::addMethod('open', function(){
if (EmptyObject::_hasAdapter('EmptyObject', __FUNCTION__))
return EmptyObject::_callAdapter('EmptyObject', __FUNCTION__, $details);
echo '<p>You have mail!</p>';
});
因为该方法是受保护的,所以会引发此错误。
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Method '_hasAdapter' was not found in class EmptyObject'