CodeSOD: List All Your Arguments

Pedro inherited a PHP application, and the previous developer had some opinions about how to handle arguments to functions. This is the pattern they used everywhere:

public function concatName($firstName, $lastName) { $names = array ($firstName, $lastName); $fullName = 'Mr.' . $names[1] . ' ' . $name[2]; return $names[0] . ' ' . $names[1]; }

There's a lot to unpack here. First, the $fullName line doesn't work as intended, since arrays in PHP are zero indexed. I suspect the developer responsible was trying to figure out how to do this task, and left behind one of their experiments.

But "smash the arguments into an array" is a common feature of this developer's code. It happens in nearly every method. Why? No idea. Do they also use argument unpacking to pass arrays as arguments? Is it all just arrays? Is everything an array? Am I an array?

Did I just type array too many times? Can you get semantic satiation in text?

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *