Created
November 23, 2016 09:54
-
-
Save SebDeclercq/7581a729c6696845eaa728325a12071c 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 T | |
{ | |
protected $methods = array(); | |
public function addMethod($name, $closure) { | |
$this->methods[$name] = $closure->bindTo($this, __CLASS__); | |
} | |
function __call($method, $args) { | |
if (is_callable($this->methods[$method])) { | |
return call_user_func_array($this->methods[$method], $args); | |
} | |
} | |
} | |
$t = new T; | |
$t->addMethod("hello", function($name) { | |
echo "Hello $name !"; | |
}); | |
$t->hello("Seb"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment