脚本宝典收集整理的这篇文章主要介绍了php – 匿名函数/关闭并使用self ::或static ::,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
现在我得到这个错误:
EmptyObject::addMethod('oPEn',function(){ if (static::_hasAdapter(get_class(),__FUNCTION__)) return self::_callAdapter(get_class(),__FUNCTION__,$details); echo '<p>You have mail!</p>'; });
抛出这个错误:
和
//Add the functions EmptyObject::addMethod('open',function(){ if (EmptyObject::_hasAdapter('EmptyObject',__FUNCTION__)) return EmptyObject::_callAdapter('EmptyObject',$details); echo '<p>You have mail!</p>'; });
abstract class EmptyObject { PRotected static $methods = array(); final public static function __callStatic($name,$arguments) { return call_user_func(self::$methods[$name],$arguments); } final public static function addMethod($name,$fn) { self::$methods[$name] = Closure::bind($fn,NULL,__CLASS__); } final protected static function protectedMethod() { echo __METHOD__ . " was called" . PHP_EOL; } }
现在传递给EmptyObject :: addMethod()的任何匿名函数都将在EmptyObject类的范围内运行
EmptyObject::addMethod("test",function() { self::protectedMethod(); }); // will output: // EmptyObject::protectedMethod was called EmptyObject::test();
以上是脚本宝典为你收集整理的php – 匿名函数/关闭并使用self ::或static ::全部内容,希望文章能够帮你解决php – 匿名函数/关闭并使用self ::或static ::所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。