Jump to content

php supports function overloading or not?


johnmerlino1

Recommended Posts

First, I read PHP does not support function overloading. Then later in the book in chapter of OOP, it states:
 

 

PHP supports function overloading, which means that you can provide more than one
function with the same name and different numbers or types of parameters.

 

 

So does it support function overloading or not? And of course my definition of function overloading is what you get in the Java programming language.

The quote is bollocks, and it worries me that obvious nonsense like this is accepted into a book. Interestingly, chapter 5 says the exact opposite (the truth): You cannot have multiple functions/methods with the same name but different parameters. PHP doesn't even have type declarations of parameters (there's type hinting, but it's limited to classes and arrays).

 

However, the PHP core developers themselves are hopelessly confused about the term “overloading”: On the one hand, they've redefined it to describe magical methods like __set() and __get(). Then it's used with yet another definition in the mbstring extension where it simply means that the default string functions are replaced with mbstring functions.

 

So now we have three different definitions: The “official” one as used everywhere outside of PHP, and two different definitions used in the PHP world. How helpful.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.