05-php中的方法重载

来源:互联网 发布:天刀明月心捏脸数据女 编辑:程序博客网 时间:2024/04/27 16:49

要点:

1.php中目前是不直接的支持方法重载的 。

2.php中通过使用__call来模拟使用方法重载。


<?php//php中的方法重载的使用     class   D{  public function test1($p){ echo "方法1";  }  public function test2($p){ echo "方法2";  }  //魔术方法  public function __call($method,$p){  if($method=="test"){  if(count($p)==1){ $this->test1($p);  }else{ $this->test2($p);  }  }  }  } $d1=new D(); //系统会自动的查找test()方法,但是没有找到test方法,系统会自动的调用__call方法 $d1->test(4); $d1->test(3,3);?>




原创粉丝点击