Inherit from a class:
<?php
class MyClass {
public function hello() {
echo "Hello World!";
}
}
class AnotherClass extends MyClass {
}
$obj = new AnotherClass();
$obj->hello();
?>
Try it Yourself »
The extends
keyword is used to derive a class from another class. This is called inheritance. A derived class has all of the public and protected properties of the class that it is derived from.
Read more about inheritance in our PHP OOP - Inheritance Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!