我有一些继承问题。 我有类似的东西类没有继承 - 类没有找到
文件a.php只会
namespace Main;
class A{
public function __construct(){ echo 'A->__construct'; }
}
和文件B.php
namespace Main;
class B extends \Main\A{
/* if I write this construct and remove extends from this class - it works - but I need to inherit it */
public function __construct(){ $a = new \Main\A(); }
public function something(){ echo 'B->something';}
}
是否有某些情况下,当类不能被继承或继承另一个类?
你包括它吗? – MightyPork
由于A和B都在相同的名称空间中定义,所以您只需要执行'B类扩展A' – Orangepill
@MightyPork yes ..如果不需要它,它不会创建实例..在B-> __construct – StellaireMan