- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
At least the original author of this code KNEW it would end up on The Daily WTF!!
Admin
What? I was going to enter the name of my new metäl bänd!
Admin
All together now, TRWTF is...
Admin
Non-php coder here. Doesn't take any real php knowledge to see that it is bad, but could someone post a proper way to do the same?
Admin
Taken from a stackoverflow answer by yours truly.
Admin
TRWTF is meta submissions [and PHP, of course]
Admin
TRWTF is intentionally writing bad code and then comment whoring.
Admin
This will almost certainly be disallowed as spam, which is a shame because it's so so so relevant to Scandinavian special characters
http://thechive.com/2012/09/26/gotta-hand-it-to-norwegians-we-cant-compete-with-this-video/
Admin
TRWTF is that the author didn't short-circuit the situation and send it in him/herself. Although, now I write it, we can't be sure the code wasn't Juho's....
Admin
use of 'magic numbers'. Ironic.
Admin
Why not simply use html_entity_decode?
Admin
TRWTF is that he left out Æ and Ø. That means he has got Swedish and Finnish covered, but not Danish and Norwegian.
I am curious what str_replace must look like in order for this to work in the first place.
Admin
I tried to read the mb_encode_numericentity() documentation, and I have to say I think that's the real WTF. Because it is:
With functions this well defined, this easy to use, and this easy to find, I have to say that the original example is a model of correctness and a definite non-WTF by comparison.
Admin
At least he wasn't Turkısh.
Admin
If you want to learn the true meaning of horror, look at the source code of the strtotime() function.
Admin
Meant that as a reply to this:
Admin
TRWTF is the linked bug report is for MySQL 5.0, not PHP 5.0.
Good catch! Fixed! -Mark
Admin
Oh, you're totally right, the code I posted above is in the opposite direction - html_entity_decode is the replacement. To convert from characters to entitites (as is done somewhere else in the original code), htmlentities is not sufficient.
Admin
Admin
Not a WTF.
Admin
Yeah, pretty dull WTF today. I'm going back to yesterday's discussion of sex, money and politics. See you there!
Admin
Use python.
That's not to say that other languages wouldn't fit the bill; python would just be my choice. But PHP really is just stupid about a lot of things. Most of it is an unintuitive mess.
Admin
TRWTF is always PHP.
Admin
He forgot about æÆ and øØ if he considers Norway and Denmark scandinavian. This guy is probably Swedish or Finn. Did he send you delicious salmiakki?
(Captcha: secundum. At least it wasn't pr1m0 nunt10!)
Admin
Priceless® CODE SOD:
http://www.mastercard.com/common/js/country_list.js
"There are some things money can't buy, for everything else there's MasterCard."
Admin
PHP, for making you jump through hoops to correctly escape and unescape HTML.
We've only had symbolic expressions since the '60s, and PHP's raison d'etre is to generate HTML. Yet here we are, in 2012, and you're supposed to litter your code with calls to escape and unescape functions.
Admin
Not a Code SOD; it's Javascript that was generated server-side.
Admin
Admin
Admin
TRWTF is that this code has nothing to do with the cited MySQL bug. Entities have to be replaced before the database, otherwise you'll be searching for "metäl" and the database won't find you "metäl".
"Text searches won't work" indeed.
Admin
Either way, this smells. The work should be done on the server, not in the browser. And if it is generated code, that's even worse, because the server is doing the work but then handing it off to the client to do it all over again!
I think some people automatically code in JavaScript because it is all they know. Which is another way of saying their I.Q. is <80 and they should never be allowed near a development environment.
But hey, it isn't like this web site needs high standards. It's just MasterCard. All they've got is millions of people's money and credit ratings in their clumsy hands.
Admin
Admin
http://www.php.net/manual/en/function.str-replace.php
"Subject ... otherwise known as the haystack"
Admin
What's wrong with that? The haystack is the item being search in... The name subject is maybe a bit strange, but there's a lot worse in php...
See, PHP is fairly consistent. The fact that html_entity_decode and htmlentities are opposites, for one. Consistent use of underscores between words, and plural form... PHP also always uses the "needle, haystack" parameter order, for example in array_search. Except for strpos and maybe some other cases.
Admin
At least he recognizes that it's ugly code. When I write ugly code, I always try to include a comment explaining why I did. That way the next programmer to look at it has a clue what's going on. Aww, who am I trying to kid. That way the next programmer to look at it doesn't think I'm a complete moron.
Admin
As a Norwegian-American, I am deeply offended at having been left out.
Admin
There is probably a WTF somewhere, inasmuch as this should not be needed. Just store the non-HTML-entities-text in the database, of course, and when it is supposed to be output in HTML - use htmlentities().
The WTF is trying to store strings with HTML entities in a database. Just bad thinking.
Admin
Is it a bad thing if your documentation requires switch statements?
Admin
TRWTF is PHP's documentation site looks almost the same as the last time I visited it: 1998!
Admin
Finland isn't part of Scandinavia , however, Finland does have Swedish as an official language.
Admin
Obligatory PHP is TRWTF link
Captcha: Saepius - Whoever wrote that was an evolutionary step behind a homo saepius.
Admin
Also Ä and Ö are used in Finnish language. And it is common to refer Å, Ä, and Ö as Scandinavian characters in Finland. And Danes and Norwegians are commonly discriminated in that field.
But the real WTF in Finnish language is that V and W are equal in alphabetic order. W is not used in modern Finnish but it is still fairly common in names and lots of computer generated alphabetic lists sort it wrong.
Admin
Read most of that, and many do not believe that article to be the whole truth: I wish bloggers would stop quoting that fractal article
Admin
Admin
str_replace is a native PHP function (www.php.net/str_replace/)
Admin
[quote=the article]when saw the following PHP code[/quote] I think you accidentally a pronoun there.
(Captcha: uxor. Juho uxored the TDWTF submission process.)
Admin
The original complain about php is still mostly true.
And most of the replys are just "That's the way it is"
But one interesting question is: What is a well designet system written in php?
I have newer seen any. The last 2 systems I looked at was Wordpress and Magento.
Wordpress is just a total fuckup which total ignores the concept of separation of code(Php) and presentation(html) and Magento seems to use a "Happy go luckey"* module system where a simple config/code error often will cause Magento to to skip an entire module without any warning or error message.
It seems like they made it this way, because they could not find a way to handle php parse errors, but I don't know if that was the cause.
But I am still looking forward to the day Php gets a proper string class which can handle unicode. Last time I checked it was scheduled for php6.
Admin
I don't understand where $field_db_value came from. The CHANGE-FROM strings are HTML. Somehow he's getting HTML into his database? Fill in a web form and submit it and what comes via POST is what the user typed, not HTML entities. Even GET mangles and un-mangles properly. Where did he get the six character string "ä" (ampersand, "a", "u", "m", "l", semi-colon) in the first place?
Admin
Admin
Nah the real WTF is that there is W in the first place.