Public, Protected, and Private
The public, protected, and private keywords describe what kind of access restriction is in place for an object’s attributes and methods. Public is the least restrictive and means that any other object or code can gain direct access. This is why code can call the erase and describePencil methods in the examples in the preceding section. The class definition states that these methods are public.
For any PHP class it is possible to declare all of the attributes and methods as public. This has its advantages and disadvantages. One advantage of public attributes is that methods are not needed to access or change them, so there is less code. A major disadvantage is that since these attributes are public, they are not ...
Get Oracle Database Ajax & PHP Web 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.