However, you have one limitation
if you use magic methods. While using reflection API, you can't investigate class
properties (we will discuss about reflection API in a later chapter). Moreover, your
class lost the "readability" and "maintainability" quite a lot. Why? See the code of
previous Student class and new Student class and you will understand that
for yourself.
Magic Methods for Overloading Class
Methods
Like overloading, and using the accessor methods, there are magic methods
to overload any method call in a class. If you are still not familiar with method
overloading, then this is a process of accessing any method that doesn't even exist in
the class. Sounds funny, right? Let's take a closer look.
There is a magic method, which helps to overload any method call in PHP5 class
context. The name of that magic method is __call(). This allows you to provide
actions or return values when undefined methods are called on an object. It can be
used to simulate method overloading, or even to provide smooth error handling
when an undefined method is called on an object. __call takes two arguments: the
name of the method and an array of the arguments passed to the undefined method.
Pages:
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65