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
In PHP, the default visibility is public.
Visibility may no change, unless when overwriting it with a trait, or in a child class.
<?php
class x {
public const X = 1;
private $property;
protected function foo() {}
}
?>
See also PHP OOP Visibility, PHP P51: Visibility Modifiers, PHP Tricks: Access control bypass
Related : Properties, Method, Static Constant