smerny Posted November 23, 2009 Share Posted November 23, 2009 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 More sharing options...
roopurt18 Posted November 23, 2009 Share Posted November 23, 2009 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 https://forums.phpfreaks.com/topic/182561-same-function-with-different-arguments/#findComment-963625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.