CodeSOD: The Last Last Name

Sometimes, you see some code which is perfectly harmless, but illustrates an incredibly dangerous person behind them. The code isn't good, but it isn't bad in any meaningful way, but they were written by a cocaine addled pomeranian behind the controls of a bulldozer: it's full of energy, doesn't know exactly what's going on, and at some point, it's going to hit something important. Such is the code which Román sends us. public static function registerUser($name, $lastName, $username, ...) { // 100% unmodified first lines, some comments removed $tsCreation = new DateTime(); $user = new User(); $name = $name; $lastname = $lastName; $username = $username; $user->setUsername($username); $user->setLastname($lastname); $user->setName($name); // And so on. } This creates a user object and populates its fields. It doesn't use a meaningful constructor, which is its own problem, but that's not why we're here. We're here because for some reason the developer behind this function assigns some of the parameters to themselves. Why? I don't know, but it's clearly the result of some underlying misunderstanding of how things work. But the real landmine is the $lastname variable- which is an entirely new variable which has slightly different capitalization from $lastName. And you've all heard this song many times, so sing along with the chorus: "this particular pattern shows up all through the codebase," complete with inconsistent capitalization. [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

Jul 3, 2025 - 15:00
 0  0
CodeSOD: The Last Last Name

Sometimes, you see some code which is perfectly harmless, but illustrates an incredibly dangerous person behind them. The code isn't good, but it isn't bad in any meaningful way, but they were written by a cocaine addled pomeranian behind the controls of a bulldozer: it's full of energy, doesn't know exactly what's going on, and at some point, it's going to hit something important.

Such is the code which Román sends us.

public static function registerUser($name, $lastName, $username, ...) {
    // 100% unmodified first lines, some comments removed
    $tsCreation = new DateTime();
    $user = new User();
      
    $name = $name;
    $lastname = $lastName;
    $username = $username;
       
    $user->setUsername($username);
	$user->setLastname($lastname);
	$user->setName($name);
	// And so on.
}

This creates a user object and populates its fields. It doesn't use a meaningful constructor, which is its own problem, but that's not why we're here. We're here because for some reason the developer behind this function assigns some of the parameters to themselves. Why? I don't know, but it's clearly the result of some underlying misunderstanding of how things work.

But the real landmine is the $lastname variable- which is an entirely new variable which has slightly different capitalization from $lastName.

And you've all heard this song many times, so sing along with the chorus: "this particular pattern shows up all through the codebase," complete with inconsistent capitalization.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow