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

  1. <?php
  2. class class_name
  3. {
  4. var $attribute;
  5. function __get($name)
  6. {
  7. return $this -> $name;
  8. }
  9. function __set($name,$value)
  10. {
  11. $this -> $name = $value;
  12. }
  13. }
  14. $a = new class_name();
  15. $a -> attribute = 5;//__set()设置属性值
  16. $a -> attribute; //__get()检查属性值
  17. ?>