Defining visibility

Deceptively, the word visibility has nothing to do with application security! Instead it is simply a mechanism to control the use of your code. It can be used to steer an inexperienced developer away from the public use of methods that should only be called inside the class definition.

How to do it...

  1. Indicate the visibility level by prepending the public, protected, or private keyword in front of any property or method definition. You can label properties as protected or private to enforce access only through public getters and setters.
  2. In this example, a Base class is defined with a protected property $id. In order to access this property, the getId() and setId() public methods are defined. The protected method generateRandId() ...

Get PHP 7: Real World Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.