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 extends 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 x {
function foo() { echo "X"; }
}
class y extends x { }
// Both methods are possible
(new x)->foo();
(new y)->foo();
?>
See also Stop using “extends” in PHP
Related : implements