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
https://forums.phpfreaks.com/topic/182561-same-function-with-different-arguments/
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)

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.