- 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
strtolower($firts)
Admin
My guess is that someone used a case sensitive file system and someone saved another file with the wrong capitalization, and they wanted to make sure only the lowercase one got processed.
The correct fix was probably elsewhere, but sometimes management won't let you insist on training the user, but instead require a stupid hack like this.
"Fixing" this probably broke that original problem again. Of course, without comments here (or in the CVS) there's no way to easily know that.
Admin
Exactly - later the results are processed and written to a lower-case filename, silently overwriting any other file of the same name.
Admin
Clean code is needed and unit tests. The unit tests should/would have a case for why the lower case condition is needed, and making the condition into a well named function would self document it.
Admin
Anyone else surprised to see strtolower() instead of a regex?
Admin
You must be new here.
Admin
More likely, some poor soul decided [probably on their own] that only directories should have uppercase letters in their names.
Admin
Not surprised in the least. In fact I applaud the use of strtolower rather than Regex. Only idiots and "heros" use Regex when there is ANY OTHER ALTERNATIVE
Admin
The first rule of regex is never use regex
Admin
You seem to have got whooshed. TRWTF is not having enough WTFery in your code
Admin
Regex's are fine as long as they follow some simple rules: They should be obvious in function if at all possible They should be clearly documented They should be avoided if there is a built in function that has the same end result (like in this 'tolower' example)
Admin
I'm sorry. I just realized your post was meant to be sarcastic. <sarc>You must surround it with the proper tags.</sarc>
Admin
Regexps are like a highway to coolness.
Admin
What, paved with roadkill?
Admin
"Logging was non-existent, ..."
When I inherit a project like this, this is the first thing I do. Then the ongoing second thing I do is log the silently swallowed exceptions. Then I am in a position to address the long-term third thing, which is to address all the hitherto undiagnosed crashes and other similar nastiness.
Admin
Heh... For once a PHP submission where PHP itself is not TRWTF. Sure, it probably doesn't help, but that sort of legacy problems can happen in any language. Been there, done that, contributed to the reverse-engineered docs in the wiki...
Admin
It doesn't do anything because the check is not case sensitive. To make it work, use ( $file === strtolower($file))
Admin
Using a convention: directories in uppercase, files in lowercase?
Admin
I submitted a good WTF article ages ago, but flavorless crud like this continues to get posted. Sigh.
Admin
https://en.wikipedia.org/wiki/HOSxP
In terms of: widely use, by-hospitals, I think HOSxP is a brilliant project.
But its code is... :-( It's very funny to go through the code, try it :-)
Admin
Aren't you the guy who wrote James Joyce?
Admin
No, that's not quite how PHP works. === is for strict comparison on types (e.g. a string against a string, instead of loosely comparing strings and ints, for example). == will work fine to compare two strings of differing case, and will return false if the case does not match. What you're thinking of is something like strcasecmp() which will do a case-insensitive comparison