时间:2021-07-01 10:21:17 帮助过:4人阅读
0) {
return $this->$a = $str;
} else {
//如果不能通过验证则抛出错误
throw new Exception( '字符串不能为空。');
}
}
public function __get($a) {
return 'The words you entered: ' . $this->$a;
}
}
$c = new example();
$c->a = 'Hello World!'; //此处将调用默认自动调用 __set()函数
echo $c->a; //此处将调用默认自动调用 __get()函数
以上就介绍了 PHP类中 __set 和 _get的用法示例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。