Courses

PHP for Laravel Developers

Visibility: public/private/protected

Summary of this lesson:
- Understand public, private, and protected method modifiers
- Explore practical implications of method visibility
- Learn about default visibility in PHP classes
- Examine when to use different visibility levels

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 16 lessons of this course? (52 min read)

You also get:

  • 73 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord