欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-21 10:29:21
...
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...