- var_dump: documentation ( source)
- phpversion: documentation ( source)
- array_merge: documentation ( source)
- is_callable: documentation ( source)
<?php
class stdObject{
public function __construct(array $params=array()){
if(!empty($params))
foreach ($params as $key => $value)
$this->{$key}=$value;
}
public function __call($methodName,$params){
$params=array_merge(array('stdObject'=>$this),$params);
if(isset($this->{$methodName})&&is_callable($this->$methodName)){
//$params就是函数的参数,这里的stdObject就是function中的$stdObject;
return call_user_func_array($methodName,$params);
} else {
throw new Exception("Fatal error: Call to undefined method stdObject::{$methodName}()");
}
}
}
echo phpversion();
$obj = new stdObject();
$obj->name = "Nick";
$obj->surname = "Doe";
$obj->age = 20;
$obj->adresse = null;
var_dump($obj);
?>