“Method overloading” may be a slightly confusing term, since it means something specific in other languages. In Java and C++, method overloading means writing different methods that have the same name, but different numbers or types of arguments, and which method is executed depends on what arguments you supply. This is particularly useful in statically typed languages (such as Java and C++). Without method overloading, you might need two differently-named methods just to handle arguments of different types (for example, a date specified as a string or a numerical timestamp).]
Overloadable method calls in PHP 5 are more general. You can overload method calls, but you have to define the overloading yourself. It works like this: if you try to call a method that’s not defined, PHP 5 will call a method called __call() instead. Then you can do whatever you want with the “failed” method call. You can execute
another method, possibly on another object, or you can give an error message that’s different from the usual one. You can even do nothing; that will cause PHP to disregard failed method calls instead of generating a fatal error. That could be useful occasionally, but in general, be careful with anything that reduces the level of error checking
and allows bugs to go unnoticed.
Overloadable method calls in PHP 5 are more general. You can overload method calls, but you have to define the overloading yourself. It works like this: if you try to call a method that’s not defined, PHP 5 will call a method called __call() instead. Then you can do whatever you want with the “failed” method call. You can execute
another method, possibly on another object, or you can give an error message that’s different from the usual one. You can even do nothing; that will cause PHP to disregard failed method calls instead of generating a fatal error. That could be useful occasionally, but in general, be careful with anything that reduces the level of error checking
and allows bugs to go unnoticed.
Comment