Jump to content

Same function with different arguments?


smerny

Recommended Posts

been awhile since I did java, but I seem to remember being able to name functions the same thing with different number of parameters... I tried this with php but it says I can not redeclare function... I suppose I could use optional parameters and just use conditional statements based on whether the parameters is the default value?

 

would be helpful or example if you want some statistics functions that will work with both known values entered or a list of numbers (in which case it would have to do more calculations to determine the values)

 

is this common practice? or is there a different way of doing it?

Link to comment
Share on other sites

PHP doesn't offer function overloading.

 

You have to:

  + Use default parameters (if they'll work in your case)

  + Use differing function names (as if you were programming in C)

  + Use unnamed and variable arguments (which will render your code difficult to use)

Link to comment
Share on other sites

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.