All pastes #2046494 Raw Edit

Miscellany

public php v1 · immutable
#2046494 ·published 2011-04-14 18:30 UTC
rendered paste body
<?phpclass A() {    private $methods = array();    private function defaultMethods() {        $this->methods['func1'] = function() { return "Foo"; };    }    public function __construct() {        $this->defaultMethods();    }    public function __construct(array $funcs) {        $this->defaultMethods();        foreach($funcs as $key => $val) {            $this->methods[$key] = $val;        }    }    public function __call($name, $arguments) {        call_user_func_array($this->$methods[$name], $arguments);    }}$a = new A();echo $a->func1();$b = new A(array('func1' => function(){ return "Bar";}));echo $b->func1();?>