|
|
|
|
|
by shaunxcode
5357 days ago
|
|
I am aware of the gnarliness of the following BUT You could do something like: class Object {
public function __call($method, $args) {
if(isset($this->$method) && $this->$method instanceof \Closure) {
$this->$method->bindTo($this);
return call_user_func_array($this->$method, $args);
}
}
}
$context = new Object;
$context->foo = "Hello World";
$context->closure = function() {
echo $this->foo;
};
$context->closure();
Once traits are in the language (5.5?) that could just be mixed in. |
|