Examine PHP V5.3.0 features under the microscope

[ Thanks to An Anonymous Reader for
this link. ]

“Class method overloading

“The term overloading in PHP is a little different from the
usual object-oriented context. In the Java™ language or C#,
an “overloaded” method is one that provides code for a range of
different parameter lists. For example, if I have a method called
draw(String str), an overloaded version can have the following
form: draw(String str, int i). This use of the method symbol name
is referred to as the method signature and, for the purposes of
overloading, the return type is ignored.

“In PHP, “overloading” is used to refer to dynamically created
methods and properties. This is in effect dynamic code, and any
such dynamic entities are processed by what are called magic
methods. You can create these magic methods in a class for a
variety of action types. Then, the overloading methods are invoked
at the point in your code where you interact with undeclared or
invisible properties or methods. This style of language overloading
provides you with a substantial degree of flexibility.

“This all sounds complicated, so look at an example to make it
more concrete. Listing 4 illustrates using PHP overloading to
invoke object and class methods.”

Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis