PHP extends Keyword

❮ PHP Keywords

Example

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 »

Definition and Usage

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.


Related Pages

Read more about inheritance in our PHP OOP - Inheritance Tutorial.


❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.