个人测试及用例,主要目的用于外部访问类内部属性的特定方法。
<?php
class getsetcall{
private $var;
/**
* PHP interceptor
*/
public function __set($key,$value)
{
return $this->$key = $value;
}
public function __get($key){
if(isset($key)){
return $this->$key;
}else{
return NULL;
}
}
public function __call($method_name,$arg_array)
{
echo "Your call function is $method_name";
print_r($arg_array);
echo "not exist.";
}
public function __unset($property) {
echo "Called when outer call private var<br>";
unset($this->$property);
}
public function __isset($property)
{
echo "Called when outer call private var<br>";
return isset($this->$property);
}
}
/*
#======= test __set and __get =======
$obj = new getsetcall();
$obj->var = "maxoi";
echo $obj->var;
*/
/*
#======= test __call =======
$o = new getsetcall();
$o->test(2,"test");
*/
/*
#======= test __unset =======
$obj = new getsetcall();
$obj->var = "a";
echo $obj->var;
unset($obj->var);
echo "Unset after.....".$obj->var;
*/
/*
#======= test __isset =======
$obj = new getsetcall();
$obj->var = "a";
echo isset($obj->var);
*/
?>