The Protected Access Control Modifier

Learn about the protected access control modifier and its use in inheritance.

Protected access modifier

The protected modifier allows us to use code from both inside the class and from its child classes. When we declare a property or a method as protected, we can approach it from both the parent and the child classes.

Example

The first example demonstrates what happens when we declare the $model property in the parent class as private, then access it from its child class.

Get hands-on with 1200+ tech skills courses.