function __get($property)
传递属性的名字,并且返回属性的值
function __set($property,$value)
传递属性的名字和新的值
function __call($method,$args)
传递方法的名字和一个数字索引的数组,数组包含传递的参数,第一个参数的索引是0.
例子:
<?php class StringCoordinateClass{ private $arr=array('x'=>NULL,'y'=>NULL); function __get($property){ if(array_key_exists($property,$this->arr)){ return $this->arr[$property]; }else{ print "Error:Can't read a property other than x & y "; } } function __set($property,$value){ if(array_key_exists($property,$his->arr)){ $this->arr[$property]=$value; }else{ print "Error:Can't write a property other than x & y "; } } } $obj=new StringCoordinateClass(); $obj->x=1; print $obj->x; print " "; $obj->n=2; print $obj->n; ?>