Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

extends

extends is an operator of the class inheritance. It indicates that a class is built from another one, or an interface is built from another interface. As such, the properties, constants and methods of the parent class or interface are available to the newly created class, unless when they are marked with private visibility.

extends is optional.

extends is unique with a class: it is not possible to extend several classes at the same time.

extends may be multiple with interfaces.

extends has a different mechanism than implements: implements provide method signature but no implementation; extends provides both.

<?php

    class Elephpant {
        function trumpet() { echo 'Elephpant'; }
    }

    class Calf extends Elephpant { }

    // Both methods are possible
    (new Elephpant)->trumpet();
    (new Calf)->trumpet();

?>

Documentation

See Also