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

Inheritance

Inheritance is a mechanism where a class is build from another class, and form a hierarchy of classes that share a set of attributes and methods.

<?php

class elephpant {
    public function trumpet() {
        echo "I am trumpet!\n";
    }
}

class calf extends elephpant {
    public function stampede() {
        echo "I am stampede!\n";
    }
}

$calf = new Calf();
$calf->stampede(); // calling the stampede method, defined only with calf
$calf->trumpet(); // calling the trumpet method, defined in elephpant, and inherited in calf

?>

Documentation

See Also