您好,欢迎访问一九零五行业门户网

php中一个类访问另一个类中的成员函数的步骤

php中一个类访问另一个类中的成员函数的方法
类里写个静态方法,用来返回$a实例,随处调用
class instance{
     private static $a;
     static function geta(){
             if(!self::$a){
                   self::$a = new a();
           }
           return self::$a;
    }
}
class a{
       function ita(){
          echo 'ita function';
}
}
class b{
      function itb(){
     //在这里取得a的单例,不会出现多次实例化的现象
    $a=instance::geta();   
     $a->ita();
}
其它类似信息

推荐信息