__call()重载,简单的授权

来源:互联网 发布:淘宝新品上架时间 编辑:程序博客网 时间:2024/05/22 01:44
  1. <?php
  2. class Test{
  3.     private $arr =array('x'=>null,'y'=>null);
  4.     function display($count){
  5.         for($i=1;$i<$count;$i++){
  6.             print "hello".$i.'<br>';
  7.         }
  8.         return $count;
  9.     }
  10.     
  11. }
  12. class TestDelegator{
  13.     private $obj;
  14.     function  __construct(){
  15.         $this->obj=new  Test();
  16.     }
  17.     function  __call($method,$args){
  18.         return call_user_func_array(array($this->obj,$method),$args);   
  19.     }
  20. }
  21. $obj = new TestDelegator();
  22. //用TestDelegator的实例调用Test的方法法
  23. print $obj->display(10);
  24. ?>
原创粉丝点击