Home  >  Article  >  Backend Development  >  php __get(), __set() functions to access attributes_PHP tutorial

php __get(), __set() functions to access attributes_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:52:40908browse

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...
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