Created
February 11, 2015 11:30
-
-
Save MadFaill/fe18ed03167c558dc69d to your computer and use it in GitHub Desktop.
Monkey Object :D
This file contains 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 | |
include "MonkeyObject.php"; | |
$a = new MonkeyObject; | |
$a->e = function () { | |
return 123; | |
}; | |
$a->b = function ($p) { | |
return $p; | |
}; | |
var_dump($a->e()); | |
var_dump($a->b(12)); |
This file contains 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 | |
final class MonkeyObject | |
{ | |
/** | |
* @var \Closure[] | |
*/ | |
private $l=[]; | |
public function __set($param, \Closure $value) | |
{ | |
$this->l[$param] = $value; | |
} | |
public function __call($method, array $args = []) | |
{ | |
return call_user_func_array($this->l[$method], $args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment