发布网友
共2个回答
热心网友
当在给给不可访问属性赋值时 先调用__set(),要怎么通俗。。。。
热心网友
class c{
public function __set($name, $value) {
$this->$name = $value;
}
public function __get($name){
if($this->$name){
return $this->$name;
}else{
return 'sop';
}
}
}
$a = new c;
$a->p = 'on the tap/step';
var_export( $a->p);
var_export( $a->d);
追问我想问这个set和那个构造函数有啥区别,两个都是可以往里面去传值