¿Es posible acceder a las clases/objetos mencionados como self
, static
y $this
en devoluciones de llamada anónimas en PHP? Al igual que este:
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
});
}
}
¿Hay alguna manera de hacer que se comporte como con variables habituales, utilizando use(self)
cláusula?
Desde PHP 5.4, es posible usar $ this. –
* (relacionado) * [PHP 5.4 - 'cierre $ this support'] (http://stackoverflow.com/questions/5734011/php-5-4-closure-this-support/5734109#5734109) – Gordon