PHP extends Keyword

PHP final Keyword
PHP endswitch Keyword

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();
?>
PHP final Keyword
PHP endswitch Keyword

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top