I’ve seen a few people ask a similar question. But I do need a little more clarification on this particular subject.
I have several functions that pass several arguments. I even have a few that are about 10 arguments. (didn’t initially plan it, simply grew over time)
I don’t have any problems looking at my source code to find out what the 7th argument is, but it does get tedious. Most of the time I know what arguments to pass, just not the position.
I had a few ideas to simplify the process for me.
a) pass 1 argument, but divide everything with some delimiter. (but that’s a bad idea!, since I still need to remember the position of each.
function myfunc('data|data|data|'){
// explode the string
}
b) pass an array with key and values, and look for the key names inside my function, and act accordingly.
function myfunc(array('arg1' => 'blah blah', 'arg2' => 'more blah')){
// loop through the array
}
c) keep it as it is.
function myfunc($arg1,$arg2,$arg3,$arg4,$arg5........){
// yay
}
So, I’m seeking other options and better ideas for handling functions with growing argument lists.
b) (an associative array) is by far the easiest, most adaptible (as it allows simulating default keyword arguments), and least error-prone variant.