Created
June 15, 2012 12:58
-
-
Save cs278/2936356 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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