Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Visibility: public/private/protected

Premium
3 min read

When discussing OOP, we must touch the "visibility" topic, meaning the public/private/protected keywords before properties/methods. When to use which?

For example, when creating methods in Controllers, we're probably used to "blindly" type public function ...:

EveryControllerEver.php

public function index()
{
// ...
}
 
public function create()
{
// ...
}

Question: in what cases would we change the methods to private or protected?

First, let me tell you...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

N
Napping7269 ✓ Link copied!

"protected: property/method can be accessed within the class itself and by inheriting and parent classes but not in their objects" This statement appears to be incorrect. You can't access the protected property of a child from the parent class.