Access Modifiers

Chapter 2 identified access modifiers as an essential element of an OO language. PHP 5 gives us everything we would expect in this area. In previous versions of PHP there was no support for data protection, meaning that all elements of a class were publicly accessible. This lack of access modifiers was probably the biggest disincentive to using objects in PHP 4.

Note:

A notion closely related to data protection is information hiding. Access modifiers make information hiding possible by exposing an interface (as defined in Chapter 2). This is also referred to as encapsulation of an object.

Get Object-Oriented PHP 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.