如何菊花链PHP类

Jas*_*man -1 php class object models

我想做这个.

$ppl->tech->ceo->apple();
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

Ben*_*Ben 5

例如:

class ppl {
  public $tech;

  public function __construct(){
    $this->tech = new tech();
  }
}

class tech {
  public $ceo;

  public function __construct(){
    $this->ceo = new ceo();
  }
}

class ceo {
  public function __construct(){

  }

  public function apple(){
    echo 'Hello.. I\'m apple.';
  }
}
Run Code Online (Sandbox Code Playgroud)

  • +1的确切答案 (2认同)