Stack Overflow Code WTF

  1. Comments (5)

If you try to hang around Stack Overflow for a while watching questions and answers there, you'll surely go postal. Sometimes I can't trust my eyes. WHAT someone have to have in their mind to produce a code like that?

So I decided to start collecting such WTFs.

  1. My favorite ingenious function. Note that the author's intent was not to remove null values, which would have made at least some sense, but to remove keys that do not exist in the array, as it was asked in the OP (to prevent 'Undefined index error'). Just hilarious.
  2. That's a link to my own answer, which explains why the accepted answer is ridiculously wrong. And you may compare the voting. NB! Please to not correct the voting! I am by no means is after any reputations points, and what I want is to keep this post as illustrative as it is at the moment (46/-1).
  3. A somewhat petty issue, the guy confused a reference with a resource. The most funny part is the initial voting. This post had +7 score. Again, you can make a picture of a regular SO participant and their habit of voting.
  4. Again, it is voting that makes you WTF?! The answer is outright wrong, current(), as the name suggests, is giving you the current element, not the first one as it was asked in the OP. Same for the key() as well.
  5. The initial voting weren't that high, but the answer is still essentially wrong: the very difference of mysqli_insert_id() from LAST_INSERT_ID() is that the former won't give you an id from the last successful query but from the very last insert query, as it said in the manual. The sad part here, mods deleted my comment explaining this stuff and asking the guy to delete this answer so not to confuse people. Why mods are so determined in keeping this shit intact is a puzzle.
  6. My own answer again that is basically a WTF about the accepted answer that helps the OP to take a steady aim and shoot himself in a foot.
  7. Voting inconsistency again The initial answer was just a showcase of illiteracy, it's wrong on so many levels, making absolutely no sense. Neither being of any help for someone with a similar error. Nevertheless, it gets a metric shit ton of upvotes. The only question, who are all those people? What do they think?
  8. Probably the most awful thread ever. As usual, it solves a non-existent problem. Solving non-existent problems is a trademark of Stack Overflow where people never question a question but always eager to answer the most blunt and direct way. And as usual, the most astonishing thing is the voting. As awful solution as the following code to count rows in the table has a whooping score of 20 "karma" points:

    function countAll($table){
       
    $dbh dbConnect();
       
    $sql "select * from `$table`";
       
    $stmt $dbh->prepare($sql);
       
    $stmt->execute();
       return 
    $stmt->rowCount();
    }

Related articles: