php meta programming
<?phpclass 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();
?>
页:
[1]