Stack Overflow Code WTF
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.
- 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.
- 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).
- 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.
- 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.
- The initial voting weren't that high, but the answer is still essentially wrong: the very difference of
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.
- 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.
- 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?
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:
$dbh = dbConnect();
$sql = "select * from `$table`";
$stmt = $dbh->prepare($sql);