Jump to content

php supports function overloading or not?


Go to solution Solved by Jacques1,

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.

  • Solution

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.