当前位置:Gxlcms > PHP教程 > php__get(),__set()函数来实现对属性的访问_PHP教程

php__get(),__set()函数来实现对属性的访问_PHP教程

时间:2021-07-01 10:21:17 帮助过:11人阅读

class class_name
{
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()检查属性值

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632477.htmlTechArticleclass class_name { var $attribute; function __get($name) { return $this - $name; } function __set($name,$value) { $this - $name = $value; } } $a = new class_name(); $a - attribute...

人气教程排行