CKTIS / PHP
Keyword extends
A class extends one immediate parent and inherits its accessible implementation.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
class PriorityOrder extends Order {}A class extends one immediate parent and inherits its accessible implementation. An overriding method can call the ancestor implementation with parent::. A concrete override must preserve the method contract. Interfaces use extends to inherit from one or several interfaces.
class Order {protected function base():int{return 10;} public function total():int{return $this->base();}}
class PriorityOrder extends Order {public function total():int{return parent::total()+3;}}
echo (new PriorityOrder())->total();
13
Examples
<?php
class Order {protected function base():int{return 10;} public function total():int{return $this->base();}}
class PriorityOrder extends Order {public function total():int{return parent::total()+3;}}
echo (new PriorityOrder())->total();
Result
13