访问php类中未定义的属性时会调用__get()方法,给未定义的属性赋值调用__set()方法
以__get()为例,说明php拦截器的用法
1 <?php 2 3 class A{ 4 function __get($value){ 5 $method = "get{$value}"; 6 if(method_exists($this,$method)){ 7 return $this->$method(); 8 } 9 10 } 11 function getName(){ 12 return "jxu"; 13 } 14 } 15 16 $a = new A(); 17 print $a->name;