如何在 PHP 中调用另一个类函数


How to call another class function in PHP

我的问题类似于从另一个类PHP调用函数中的函数,但它的答案对我不起作用。

基本上这就是我想做的。

在"a.php"中,我定义了A类。

class A{
  function ab(){}
  function cd(){}
  function ef(){}
  ...
}

在 'b.php' 中,我想定义可以调用类 A 中的函数的类 B。 这是我放的,但似乎不起作用。

class B{
  function xy(){
    require 'a.php';
    $a = new A();
    $this->x = $a->ab();
    $this->y = $a->cd();
    return $a->ef();
  }
}

谁能指出我正确的方向? 谢谢

===

=====

更新:为了使我的问题更清楚,我又举了一个例子。

class Person{
  function firstName(){return $this->firstName;}
  function lastName() {return $this->lastName;}
  function address()  {return $this->address;}
  ...
}
class Car{
  function ownerInfo(){
     $owner = array();
     require 'person.php';
     $p = new Person($this->ownerID);
     $owner['firstname'] = $p->firstName();
     $owner['lastname']  = $p->lastName();
     $owner['address']   = $p->address();
     //I am sure the data is there, but it returns nothing here
     return $owner;  
  }
}

像这样尝试

class B extends A{
  function xy(){
    require 'a.php';
    $a = new A();
    $this->x = $a->ab();
    $this->y = $a->cd();
    return $a->ef();
  }
}