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

Visibility

Properties, methods and classes may have a visibility. It limits the scope of the definition:

  • private: to the current class
  • protected: to the current class hierarchy, parents and children classes
  • public: to all the code
  • var: to all the code, deprecated

The default visibility is public. The visibility may be omitted when using another option, such as final, static. It is recommended to always specify the visibility explicitly.

Visibility may no change, unless when overwriting it with a trait, or in a child class.

Visibility may be by-passed with class-invasion, where an object of one class may access another object’s property, as long as they are from the same class or family.

<?php

    class Elephpant {
        public const HABITAT = 1;

        private $tusk;

        protected function trumpet() {}
    }

?>

Documentation

See Also