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

Private Visibility

The private keyword is part of the three keywords to define visibility of a method, property or class constant. It is the strictest level of visibility: it restricts usage to the current class only. A child class can redefine it, but it cannot the parent’s: the reverse is also true.

The private keyword cannot be used with the final keyword: a private method is not visible in the child classes, and can’t also be overridden.

The private keyword cannot be used with the abstract keyword: a private method is not visible in the child classes, and can’t also be overridden.

<?php

    class Elephpant {
        private const HABITAT = 1;

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

?>

Documentation

See Also