【发布时间】:2011-11-10 19:26:04
【问题描述】:
根据这里的答案:Getter and Setter? 以下函数应该可以工作,但是它不会产生任何输出。
<?php
class UserInfo{
private $username;
private $privileges;
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
public function __set($property, $value) {
if (property_exists($this, $property)) {
$this->$property = $value;
}
return $this;
}
}
$user=new UserInfo;
$user->__set($username,"someuser");
echo $user->__get($username);
?>
我在这里做错了吗?
【问题讨论】: