saundy 发表于 2017-3-20 10:04:14

php meta programming

<?php
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();
?>
页: [1]
查看完整版本: php meta programming