CHAPTER 21

image

Overloading

Overloading in PHP provides the ability to add object members at runtime. This is done by having the class implement the overloading methods __get, __set, __call and __callStatic. Bear in mind that the meaning of overloading in PHP is different from many other languages.

Property overloading

The __get and __set methods provide a convenient way to implement getter and setter methods, which are methods that are often used to safely read and write to properties. These overloading methods are invoked when using properties that are inaccessible, either because they are not defined in the class or because they are unavailable ...

Get PHP Quick Scripting Reference 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.