__get __set , .
. , .
:
protected $bark = 'woof!';
protected $foo = 'bar';
public function __get($key) {
if (isset($this->$key)) {
return $this->$key;
}
}
public function __set($key, $val) {
if ($key=="foo") {
$this->$key = $val;
}
}
- , :
public $timestamp;
public function __set($var, $val)
{
if($var == "date")
{
$this->timestamp = strtotime($val);
}
}
public function __get($var)
{
if($var == date)
{
return date("jS F Y", $this->timestamp);
}
}
, __set, . , , , , /.