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...
- Indicate the visibility level by prepending the
public
,protected
, orprivate
keyword in front of any property or method definition. You can label properties asprotected
orprivate
to enforce access only through publicgetters
andsetters
. - In this example, a
Base
class is defined with a protected property$id
. In order to access this property, thegetId()
andsetId()
public methods are defined. The protected methodgenerateRandId() ...
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.