要通过PHP的parent关键字访问父类属性,可以使用以下语法:
class ParentClass {
public $parentProperty = 'Parent Property';
}
class ChildClass extends ParentClass {
public function getParentProperty() {
return $this->parentProperty;
}
}
$child = new ChildClass();
echo $child->getParentProperty(); // 输出 'Parent Property'
在子类中,可以使用$this->parentProperty
来访问父类的属性。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:java父类能否访问子类属性