php文档中Closure::bind
包含static
匿名函数声明中的示例。为什么?如果将其删除,我找不到差异。
与:
class A {
private static $sfoo = 1;
}
$cl1 = static function() { // notice the "static"
return self::$sfoo;
};
$bcl1 = Closure::bind($cl1, null, 'A');
echo $bcl1(); // output: 1
没有:
class A {
private static $sfoo = 1;
}
$cl1 = function() {
return self::$sfoo;
};
$bcl1 = Closure::bind($cl1, null, 'A');
echo $bcl1(); // output: 1
正如您所注意到的,这并不重要。
就像static
在类方法上使用关键字一样。如果您未在方法中进行引用,则不一定需要它$this
(尽管这确实违反了严格的标准)。
我想PHP可以解决您的问题Closure
,A
因为第null
2个参数可以静态访问bind()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句