• Quite (unregistered)

    $Frist = "Frist" If (isset($Frist)) { if (frist == "") { $Frist = "Frist" } }

  • Guess Guess Guess Guess (unregistered)

    My guess would be, that the commented-out ones are the ones that are actually used. :p

  • Ron Fox (google)

    TRWTF is rules given without supporting context.

  • Someone (unregistered)

    And then they check a post variable without confirming that it's set...

    Something really nice about PHP in this regard, however, is that you can write if(isset($var) && $var=='x')); without any issues. Or even write a function that you can pass in the variable name and (using variable variables!) have it return null if it doesn't exist.

  • Ian Tester (google)

    Cargo-cult programming in PHP? I am shocked! Shocked to my core!

  • Mike5 (unregistered)

    Submitted from...

    Submitted from where? Don't leave us hanging! I have to know where it was submitted from!

    Anxiously awaiting your reply, Mike5

  • Slartibartfast (unregistered)

    Nonono, this is perfectly fine code! This guy is just making his code multi-thread safe! Because then the scheduler might interfere exactly in between the first set command, schedule a different thread, which then unsets the variable again, and as soon as the first thread is scheduled again, it of course cannot rely on the variable still being set. So he needs to check that again. You see, this is totally great code!

    Except...he should really add another check after the first check, because the scheduler could interrupt him right AFTER the check, but before the actual use. And then another check after this check. And another. And another. And another. And another.

    Phew. So that's why they all say that multi-threading is damn hard!

  • Appalled (unregistered)

    This is not at all junk code.

    It guarantees that the variables are 0, even if they arrived as an empty string. Otherwise the empty string could carry forward into a numeric calculation, or a DB Update to a numeric column, and crash. PHP will likely handle the numeric issue with its datatype-less methodology (turning "" into 0) but I don't have the time to try and prove something I never do. DB updates (and it SURE looks like that's where these guys are headed) WILL crash for example if they issue an:

    "Update tblMonthlyXXX SET colDIDSthisMonth = , WHERE whatever=whatever"

  • Frank (unregistered)

    "See if you can guess each ones!"

    It's becoming more and more obvious that the apparent horrendous spelling and absolute lack of editing in these posts is actually just an attempt to drive additional comments to make the blog look popular.

  • Ashley Sheridan (unregistered) in reply to Appalled

    Erm, that's not really how it works. If you have an assignment line setting a variable to 0, it will be 0. No empty string values are going to "carry forward" from somewhere else...

  • Paul Neumann (unregistered)
    if (isset($GET)) {
        $password = $GET["password"]
    }
    
  • Alex Vincent (google)

    So is this the first Monday of the month, so I can declare a fizzbin?

  • Guess-the-guest (unregistered)

    Forget all that logic crud... best Spock line Nimoy ever delivered:

    "I would advise youse to keep dialin', Oxmyx."

  • Herby (unregistered)

    Actually, Leonard Nimoy was in an episode of The Untouchables in 1962. Maybe the line wasn't hard to deliver!

  • Doo Shpag (unregistered) in reply to Guess-the-guest

    Interesting that Bela's last name was clearly "Okmyx"; it was even written out on the wall, but everyone calls him "Oxmyx". Not one of the better writing efforts in TOS.

  • Let the flame-war begin. (unregistered) in reply to Doo Shpag

    There were better writing efforts in TOS?

  • Ulysses (unregistered)

    I think TRWTF is Appalled again.

  • Appalled (unregistered)

    OK, I freaking read it backward. I thought it said IF (!(isset(whatever))) ................... I'm too old for this. I can code it but I can't read it unless it's my own.

  • Verisimilidude (unregistered) in reply to Let the flame-war begin.

    Actually the first two years of TOS are generally considered well written. After the second season the network was going to cancel it but fan letters and petitions convinced them to reverse course. However it brought new oversight and forced a sequence of truly awful 'kirk goes to planet - beautiful woman falls in love with Kirk - aliens attack - kirk defeat aliens but woman is lost to him' shows that sealed the fate of TOS. After that season not many wanted to do another letter writing campaign.

  • jmm (unregistered) in reply to Ron Fox

    My favorite was in an excel spreadsheet which had a formula not working as desired. After some time puzzling over it, I come back and say "so, the number in this cell represents the number of hours worked in a day, right?" to which the reply was, "I don't know, the last guy that did it just told me to put an 8 there, so I did."

  • CrazyEyes (unregistered)

    Man, for some reason I really want to buy some fancy watches so I can look stylish while I write my next essay.

  • Ulysses (unregistered)

    I rest my case.

  • Someone (unregistered) in reply to Appalled

    Turns out an easier way to guarantee that the variables are 0 is to just set them to 0. That tends to work.

  • markm (unregistered)

    Did this developer need to meet a quota for LOC per day or something?

  • xx (unregistered) in reply to Frank

    You are an absolute idiot who misses any sense of humour which makes this site look bad.

  • <a href="http://writemypersonalstatement.net/">writemypersonalstatement.net</a> (unregistered) in reply to Guess Guess Guess Guess

    I think you are so wrong! That's impossible

  • Peter Wolff (unregistered)

    TRWTF here is that the coder forgot the else branch - in case the variable wasn't set to an empty string, but the set op failed altogether.

    And to be really sure they ought to have used a loop ending in

    until (isset(varname) && (varname==<desiredValue>))

Leave a comment on “A Piece of the Variable”

Log In or post as a guest

Replying to comment #:

« Return to Article