【发布时间】:2019-08-03 18:23:00
【问题描述】:
我有一个场景,我有三个单独的类文件 A.php、B.php、C.php。
A.php 是独立文件,有一些功能,'B' 扩展 'A','C' 扩展 'B'。
在“C.php”文件中,我可以访问“B.php”的功能,但不能访问“A.php”的功能。
这是我的结构 -
在 A.php -
class A {
public function testA(){
echo "AA";
}
}
在 B.php -
class B extends A{
public function testB(){
echo "BB";
}
}
在 C.php 中 -
class C extends B{
//Here i am able to call class B's function like
public function testC(){
$this->testB();
}
//but not able to call Class A's function
public function testC1(){
$this->testA(); // Here its giving error
}
}
请让我知道这样做是否正确。如何在“C.php”中访问“A.php”函数
问候
【问题讨论】:
-
什么错误?! 3v4l.org/3E2Z7
-
更新后的代码有效,所以我不知道您现在遇到了什么问题。然而,这是一个非常奇怪的例子。
testC()和testC1()没有理由存在,因为您可以直接调用testA()和testB()。
标签: php class inheritance multiple-inheritance