Skip to content

Instantly share code, notes, and snippets.

@cs278
Created June 15, 2012 12:58
Show Gist options
  • Save cs278/2936356 to your computer and use it in GitHub Desktop.
Save cs278/2936356 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
public function __set($method, Closure $callback) {
$this->methods[$method] = $callback->bindTo($this, $this);
}
public function __call($method, $args) {
return call_user_func_array($this->methods[$method], $args);
}
private function doSomething() {
return "Hello World!";
}
}
$test = new Foo;
$test->sayHello = function() {
return $this->doSomething();
};
var_dump($test->sayHello());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment