php meta programming

阅读更多
class C1 {
public $c;

public function __construct() {
$this->c = 'haha';
}

public function __call($method, $args) {
if (!empty($args))
        return call_user_func_array($this->$method, $args);
       else
       return call_user_func($this->$method);
    }
}

$obj = new C1();
$hello = function($title) use ($obj) {
print("hi ${title} hello the world\n");
};
$obj->hi = function() {
echo "hi\n";
};
$obj->hello = $hello;
$obj->hello('nathan');
$obj->hi();
?>

你可能感兴趣的:(PHP,C,C++,C#)