In this article, you will learn how to derive a class from another class in PHP. The extends keyword in PHP 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.
examples of the EXTENDS keyword
Example 1. In this example, we inherit from a class.
<?php
class MyClass {
public function hello() {
echo "Hello World!";
}
}
class AnotherClass extends MyClass {
}
$obj = new AnotherClass();
$obj->hello();
?>