PHP Anti-patterns 1: The Bug Factory Anti-pattern

I recently found a PHP function with 32 parameters. Not the first time I've seen one of these.

Long parameter lists like this should probably be avoided. Here are some of the issues:

If we guestimate conservatively that the probability of getting one parameter wrong without noticing is 1% i.e. 0.01, and we assume that the probability is independent between the parameters, then the probability of getting the whole parameter list right is 0.99^32 = 0.725 i.e. the probability of getting it wrong is 0.275 i.e. more than 25% of calls to this function will be wrong.

This function is a bug factory.

If you change the parameter list you have to change it everywhere this function is called, with similar results - more bugs.

When you factor in unit testing things get even worse. If we assume that each parameter has only two states then there are 2**32 ways of calling the function. You'd need 4 294 967 296 unit tests to cover this one function.

I'll leave you to guess the number of unit tests that were actually in place and how many of the input parameters were actually documented!