PHP - 回调函数中的自、静态或$this
2022-08-31 00:53:18
						是否可以访问被引用为 的类/对象,以及在 PHP 中的匿名回调中?就像这样:selfstatic$this
class Foo {
    const BAZ = 5;
    public static function bar() {
         echo self::BAZ; // it works OK
         array_filter(array(1,3,5), function($number) /* use(self) */ {
             return $number !== self::BAZ; // I cannot access self from here
         });
    }
}
有没有办法让它像通常的变量一样,使用子句?use(self)
 
					 
				 
				    		