//说明:基类和调用者都有:say()方法,默认指向基类的那个say();运行结果应该显示:'1'
//当基类中使用了:return static::say()后,指向为调用者的那个say();运行结果应该显示:'2'
class Eee{
public static function say(){
echo '1<br>';
}
public static function beCaller(){
return static::say();
}
}
class Fff extends Eee{
public static function say(){
echo '2<br>';
}
}
Fff::say();
//私有属性的访问和修改
class Ggg{
private $aa;
private $bb;
public function __construct($cc,$dd){
$this->aa=$cc;
$this->bb=$dd;
}
public function __get($ee){
$method='get'.ucfirst($ee);
if(method_exists($this, $method)){
return $this->$method();
}else {
return null;
}
}
public function getName(){
return $this->aa.'<br>';
}
public function getPrice(){
return $this->bb.'<br>';
}
public function __set($property,$value){
$method='set'.ucfirst($property);
if(method_exists($this, $method)){
return $this->$method($value);
}else {
return null;
}
}
private function setAa($value){
$this->aa=trim($value);
}
private function setBb($value){
$this->bb=$value;
}
}
$ggg=new Ggg('初值', 1000);
echo $ggg->aa;
echo $ggg->bb;
$ggg->aa='重写值';
$ggg->bb=2000;
echo '<hr>';
echo $ggg->aa;
echo $ggg->bb;
//方法拦截器
class Hhh{
public function __call($ff,$gg){
printf('方法名:%s,参数:[%s]',$ff,implode(',',$gg));
}
}
$hhh=new Hhh();
$hhh->demo(1,2,3,4);
echo '<br>';