Home >php教程 >php手册 >php __get(),__set()函数来实现对属性的访问

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 09:53:431175browse

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

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn