0

I have class DatabaseAccess from which I inherit two classes: TeamAccess and StatisticsAccess. Now when I create instance of TeamAccess from StatisticsAccess it is of type StatisticsAccess? What is happening here?

Heres the code

class StatisticsAccess extends DatabaseAccess {
  public function getMatchesById($matchesid) {
    $teamAccess = new TeamAccess();
    print_r(new TeamAccess);
  }
}

class TeamAccess extends DatabaseAccess {
  function __construct() {
    parent::__construct();
  }
}

print_r shows StatisticsAccess object.

4

1 回答 1

0

在 StatisticAccess 中创建 TeamAccess 类只会创建一个 TeamAccess 类,就像您在类之外创建的一样。

class StatisticsAccess extends DatabaseAccess {
    public function test() {
        $teamAccess = new TeamAccess();
        //print_r(new TeamAccess);
        echo "teamAccess var class: " . get_class($teamAccess);
        echo "<br/>this class: " . get_class($this);
    }
}

$sa = new StatisticsAccess;
$sa->test()
?>

回报:

//teamAccess var class: TeamAccess
//this class: StatisticsAccess
于 2013-03-27T12:04:10.170 回答