PHP头条
热点:

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();
}

www.phpzy.comtrue/phprm/39661.htmlTechArticlephp中一个类访问另一个类中的成员函数的步骤 php中一个类访问另一个类中的成员函数的方法 类里写个静态方法,用来返回$a实例,随处调用 class instance{ private static $a; static function getA(...

相关文章

PHP之友评论

今天推荐