21

If I disregard all Wordpress code examples, this must have been one of the best examples of bad code. It took minutes to understand what it does.

Comments
  • 2
    If I had the dude who wrote these lines in front of me I wouldn't know where to start to yell at him
  • 5
    Only the first lines of code makes me yell.

    "$out[2] = $outNew;
    $matchesArray = $out[2];"

    - What if we make PHP do more work?
  • 4
    @NotFound maybe the dude didn't know about the usleep() function...
    Or he charged for lines of code written.
  • 0
    @GodHatesMe precisely because of that, I was staring into the abyss for a couple of minutes. Code had to make sense for me, and this did not, until I realized that it's completely redundant
  • 0
    Yes... And No...

    PHP, especially array handling, is due to typing, one hell of a bitch.

    If I'm not mistaken, depending on the version and error configuration, this code can do very different things.

    If the matchesArray is an array with holes or associative, this way of putting together the values assures that the final variable contains a numerical indexed array without holes - if the variable in the array at index $i does not exist, it's value is null now...

    This is a a very cumbersome and edgy corner case, but dependent on what happens with the result array, IT can be very important.

    Not redundant but very bad written.

    array_fill / array_value / range, depending on situation, are netter suited.
  • 0
    @IntrusionCM it was after a regex match. That's what I remember. The screenshot is several years old now, I don't work on that code base any longer. But the initial data is a sequential array, with no special stuff.
  • 0
    Redundancies everywhere 😞

    This could so easily be 2 lines, 3 if you want to speed up the for loop a bit depending on the size of the array.

    Some people make me cry 😭
Add Comment