php 引用父类方法
在 PHP 中,可以使用 `parent` 关键字来引用父类的方法。`parent` 关键字用于调用当前类继承的父类中的方法。
下面是一个示例,展示了如何在子类中引用父类的方法:
```php
class ParentClass {
    public function parentMethod() {
        echo "这是父类的方法。";
    }
}
class ChildClass extends ParentClass {
    public function childMethod() {
        parent::parentMethod(); // 引用父类的 parentMethod 方法
        echo "这是子类的方法。";
    }
php实例化后获取子类名称}
$child = new ChildClass();
$child->childMethod();
```
在上面的示例中,`ChildClass` 是从 `ParentClass` 继承的子类。在 `ChildClass` 的 `childMethod` 方法中,我们使用 `parent::parentMethod()` 来调用父类 `ParentClass` 的 `parentMethod` 方法。最后,通过实例化 `ChildClass` 并调用 `childMethod` 方法,将输出以下内容:
```vbnet
这是父类的方法。这是子类的方法。
```
这样,你就可以在子类中引用并调用父类的方法了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。