php __get(),__set()函数来实现对属性的访问
程序员文章站
2022-06-01 08:06:42
...
class class_name
{
var $attribute;
function __get($name)
{
return $this -> $name;
}
function __set($name,$value)
{
$this -> $name = $value;
}
{
var $attribute;
function __get($name)
{
return $this -> $name;
}
function __set($name,$value)
{
$this -> $name = $value;
}
}
$a = new class_name();
$a -> attribute = 5;//__set()设置属性值
$a -> attribute; //__get()检查属性值