PHP. OOP. Propepties and methods scope

Главная » Tutorials » PHP » PHP. OOP. Properties and methods scope

We continue to learn basic principles of OOP in PHP. Today we will discuss properties/methods scope. There three modifiers in PHP:

  • public – public properties/methods can be accessed anywhere.
  • protected – protected properties/methods can be accessed in class and child classes.
  • private – private properties/methods can be accessed in which class they have been declared .

If you don’t set modifier directly for property or method, it will be as public in code. Also I notice, protected and public proreprties/methods can’t be accessed in object context.
You can read about scope in details on official php site by this link.

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This