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;
}
}
?>
See Also
- PHP protected Keyword - Visibility Modifier in PHP
- The Beginner’s Guide to Understanding Visibility in PHP