Skip to content

Instantly share code, notes, and snippets.

@MadFaill
Created February 11, 2015 11:30
Show Gist options
  • Save MadFaill/fe18ed03167c558dc69d to your computer and use it in GitHub Desktop.
Save MadFaill/fe18ed03167c558dc69d to your computer and use it in GitHub Desktop.
Monkey Object :D
<?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));
<?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