Closure Binding
A closure acquires values from its context of creation. When the closure is created in a different context than wished, one may rebind the closure to another context.
This is done with the two methods Closure::bind() and Closure::bindTo().
<?php
class Elephpant {
private static function trumpet() { return 1;}
}
$closure = function() {
// Self is undefined here, since it is not inside a class
return self::trumpet();
};
// Self now defined, and set to Elephpant
$bcl1 = Closure::bind($closure, null, 'Elephpant');
?>