• bvs23bkv33 (unregistered)


  • William Crawford (google)

    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.

  • LCrawford (unregistered) in reply to William Crawford

    Exactly - later the results are processed and written to a lower-case filename, silently overwriting any other file of the same name.

  • Matthew Killgallon (unregistered)

    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.

  • RichP (unregistered)

    Anyone else surprised to see strtolower() instead of a regex?

  • OldCoder (unregistered) in reply to Matthew Killgallon

    You must be new here.

  • Steve (unregistered)

    More likely, some poor soul decided [probably on their own] that only directories should have uppercase letters in their names.

  • Appalled (unregistered) in reply to RichP

    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

  • thegoryone (unregistered) in reply to Appalled

    The first rule of regex is never use regex

  • Carl Witthoft (google) in reply to Appalled

    You seem to have got whooshed. TRWTF is not having enough WTFery in your code

  • nb (unregistered) in reply to thegoryone

    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)

  • Appalled (unregistered) in reply to RichP

    I'm sorry. I just realized your post was meant to be sarcastic. <sarc>You must surround it with the proper tags.</sarc>

  • L337Coder (unregistered)

    Regexps are like a highway to coolness.

  • Simon (unregistered) in reply to L337Coder

    What, paved with roadkill?

  • Quite (unregistered)

    "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.

  • akozakie (unregistered)

    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...

  • p (unregistered)

    It doesn't do anything because the check is not case sensitive. To make it work, use ( $file === strtolower($file))

  • Richard (unregistered)

    Using a convention: directories in uppercase, files in lowercase?

  • Ulysses (unregistered)

    I submitted a good WTF article ages ago, but flavorless crud like this continues to get posted. Sigh.

  • someone-else (unregistered)


    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 :-)

  • . (unregistered) in reply to Ulysses

    Aren't you the guy who wrote James Joyce?

  • Ashley Sheridan (unregistered) in reply to p

    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

Leave a comment on “A Case of File Handling”

Log In or post as a guest

Replying to comment #:

« Return to Article