Function Overloading in PHP

Update: I have written about a more Java-like, argument based overloading solution here.

I’ve been trying to get a set of good basic functions included within my PHP framework and ran across a nice little trick to allow function (without a class) overloading, the code should speak for itself.

This will be the default file.

if(!function_exists("overloadableFunc") ) {
  function overloadableFunc() {
    echo "foo";
  }
}

and this will be in the overloading file (needs to be included before the default.

function overoadableFunc() {
  echo "foobar";
}

14,165 thoughts on “Function Overloading in PHP

  1. Right here is the perfect web site for anybody who hopes to understand this topic. You know so much its almost tough to argue with you (not that I actually will need to…HaHa). You definitely put a new spin on a subject which has been discussed for decades. Great stuff, just excellent!|

  2. Incredible! This blog looks just like my old one! It’s on a totally different topic but it has pretty much the same layout and design. Superb choice of colors!|

  3. It’s perfect time to make a few plans for the long run and it’s time to be happy. I’ve read this put up and if I may I desire to counsel you few fascinating things or suggestions. Perhaps you can write next articles regarding this article. I desire to learn even more issues about it!|

  4. Hey there! I’m at work surfing around your blog from my new iphone!
    Just wanted to say I love reading your blog
    and look forward to all your posts! Carry on the
    fantastic work!

    Feel free to surf to my blog: Www3.Tok2.com

  5. Good day! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept chatting about this. I will forward this post to him. Fairly certain he will have a good read. Thanks for sharing!|

  6. That is really fascinating, You’re a very skilled blogger. I’ve joined your rss feed and look forward to in quest of more of your wonderful post. Additionally, I’ve shared your web site in my social networks|

  7. It’s truly a great and helpful piece of info. I am glad that you just shared this useful information with us. Please stay us informed like this. Thanks for sharing.

  8. Hi, I do believe this is a great web site. I stumbledupon it 😉 I’m going to return yet again since i have book marked it. Money and freedom is the best way to change, may you be rich and continue to guide others.

  9. whoah this blog is great i like reading your articles. Stay up the great work! You understand, a lot of persons are looking around for this information, you could aid them greatly. |

Leave a Reply

Your email address will not be published. Required fields are marked *