Hello,
I have a general question about PHP and functions with variable parameter lists.
The question is mostly, what solution you would consider as best “style”.
The standard solution would be, to define a standard value for each parameter. Two problems arise:
1.) I do want to force the user to specify all parameters, standard values would not make sense (of course I could throw an error)
2.) I do not know which parameters were passed! Now you will say just check if a var has standard value and if so, assume it was not passed – but what about “bool” parameters (true and false, both could be passed value)
This second problem is what really makes me frustrated. How is it possible that there is no way to figure out which var was passed and which wasn’t. Even func_get_args won’t tell you…
Another solution I see pretty often is, to use one array as parameter whenever you write a constructor function. Here I see two problems again:
1.) same as above
2.) It requires the user to construct that array to pass each time he wants to create a new object. Of course (like often done) you can define a default array for object creation but this still would (most likely) have to be altered each time.
This solution therefore seems pretty ugly to me.
How do experienced PHP developers solve this dilemma?