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

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

WBOY
Release: 2016-07-13 10:52:40
Original
974 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template