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

Protected Visibility

The protected keyword is part of the three keywords to define visibility of a method, property or constant. It is the middle level of visibility: it restricts usage to the current class, its parents and children.

<?php

class Elephpant {
    public function methodY() {
        // dependency on the child class
        echo self::HABITAT;
    }
}

class AfricanElephpant extends Elephpant {
    protected const HABITAT = 1;

    public function method() {
        echo self::HABITAT;
    }
}

class Calf extends AfricanElephpant {
    public function methodY() {
        echo self::HABITAT;
    }
}

?>

Documentation

See Also