• Frist? (unregistered)

    Frist, frist, frist, etc.

  • Yep (unregistered)

    Yep, I was waiting for that

  • 1234 (unregistered)

    What happens if we need $lastlastlastlastlastlastlastlastyear or $lastlastlastlastlastlastlastlastlastyear or even $lastlastlastlastlastlastlastlastlastlastyear

    luckily we will never need $lastlastlastlastlastlastlastlastlastlastlastyear ...

  • highphilosopher (unregistered)

    What's so bad with this? Next thing you know people will be complaining about my use of $TheDayBeforeTheFirstMondayOfThisMonthLastYear.

  • (cs)

    Whenever I see such a lot of code simply copied, I wonder, have these people ever heard of loops?

    Whenever I see such a lot of code simply copied, I wonder, have these people ever heard of loops?

    Whenever I see such a lot of code simply copied, I wonder, have these people ever heard of loops?

    Whenever I see such a lot of code simply copied, I wonder, have these people ever heard of loops?

  • me (unregistered)

    what are the odds that the probeility of the month being frebruary?

  • Techpaul (unregistered) in reply to me
    by me:
    2010-02-17 09:05 • by me what are the odds that the probeility of the month being frebruary?

    Bessy says "Content Blocked"

  • Richard T. Roll (unregistered)

    Totally not a wtf. This is just an optimization so that you can access the previous years by numerical value, like this:

    $which = "";
    while (year++ != current)
      $which .= "last"
    echo $${which}year

    I've used this a lot in my programming career and I know some might disagree but tbh it's just a different approach.

  • Techpaul (unregistered)

    Having seen websites with PHP code where three groups of modules were 99.9% identical, except for the WHERE clause of what to serach the database for, nothing on websites amazes me.

    Don't even get me on the inability of some hosting companies, to understand the differences between even Windows and Linux.

    Anyway "that was so lastlastlastlastlastyear".

  • Tim (unregistered)

    ah, a good old fashioned 100% bad code indefensible WTF (and using PHP into the bargain)

    this is what we like to see

  • Dascandy (unregistered)

    Imagine the code for the date-of-birth field...

  • (cs)

    Optimize!

    <?php
    $thisyear=date("Y");
    $lastyear=$thisyear-1;
    $lastlastyear=$lastyear-1;
    $lastlastlastyear=$lastlastyear-1;
    $lastlastlastlastyear=$lastlastlastyear-1;
    $lastlastlastlastlastyear=$lastlastlastlastyear-1;
    $lastlastlastlastlastlastyear=$lastlastlastlastlastyear-1;
    $lastlastlastlastlastlastlastyear=$lastlastlastlastlastlastyear-1;
    ?>
    
  • (cs)

    Geez, don't they realize the numberline goes in two directions?

    <?php
    $thisyear=date("Y");
    $lastyear=date("Y")-1;
    $lastlastyear=date("Y")-2;
    $lastlastlastyear=date("Y")-3;
    $lastlastlastlastyear=date("Y")-4;
    $lastlastlastlastlastyear=date("Y")-5;
    $lastlastlastlastlastlastyear=date("Y")-6;
    $lastlastlastlastlastlastlastyear=date("Y")-7;
    $nextyear=date("Y")+1;
    $nextnextyear=date("Y")+2;
    $nextnextnextyear=date("Y")+3;
    $nextnextnextnextyear=date("Y")+4;
    $nextnextnextnextnextyear=date("Y")+5;
    $nextnextnextnextnextnextyear=date("Y")+6;
    $nextnextnextnextnextnextnextyear=date("Y")+7;
    ?>
  • Appellles (unregistered)

    Shoemaker, stick to your $last.

  • (cs)

    I wonder what would happen if they set error_reporting to report E_NOTICE as well...

  • (cs)

    I decided to improve the code to a degree:

    <?php
    $thisyear=date("Y");
    $math = round((($thisyear * 2) + 4) /2 - 2); 
    $lastyear=round((($math * 4) + 4) / 4 - 2);
    $lastlastyear=round((($math * 6) + 4) / 6 - 2);
    $lastlastlastyear=round((($math * 8) + 4) / 8 - 3);
    ?>
    

    You see, you grab a random equation, and apply it randomly across the board, and you get the same results, while having crazy code. Job Security.

  • me_again (unregistered) in reply to Dascandy
    Dascandy:
    Imagine the code for the date-of-birth field...
    +1

    captcha: enim -> Eminems little brother

  • Anon (unregistered) in reply to me_again

    Could have been worse:

    $year2008 = 2008; $year2007 = 2007; $year2006 = 2006; etc.

    I mean, this is php after all.

  • (cs) in reply to Anon
    Anon:
    ... I mean, this is php after all.

    PHP isn't a bad scripting language. It's just that 99% of the PHP coders give the rest of us a bad name. I use it for server-side coding (both windows/linux) when I need a script to do something, and I don't have the time to build a real app. Handy little system in a pinch.

  • (cs) in reply to me
    me:
    what are the odds that the probeility of the month being frebruary?
    The frobbitz on the jim slam blempglorf bandersnatch!
  • (cs) in reply to Anon
    Anon:
    Could have been worse:

    $year2008 = 2008; $year2007 = 2007; $year2006 = 2006; etc.

    I mean, this is php after all.

    Or

    $year = 2010; $yearlast = 2009; $yearlastlast = 2008; etc

    with an optional comment saying "TO DO: Changes years on Jan 1st"

  • M.C. (unregistered)

    LastYearToInfinity...

  • Jared (unregistered)

    That'll fail on a leap year. ;-)

  • grizz (unregistered) in reply to Richard T. Roll
    Richard T. Roll:
    I've used this a lot in my programming career and I know some might disagree but tbh it's just a different approach.

    I've used cannibalism a lot in my food-procuring career and I know some might disagree but tbh it's just a different approach.

    Sometimes "bad" really is bad, not just different.

  • raluth (unregistered)

    Pah; this story is just so date("Y")-1

  • (cs)

    Well, on embedded systems like Bessy, it's much more efficient to unroll the loop. Paula Bean taught me that.

  • APK (unregistered)

    TRWTF is the lack of underscores. It should be "$last_last_last_last_year" which is much more readable and maintainable.

  • (cs)

    What REALLY surprises me is that PHP doesn't have a built-in method for this year minus seven.

    I suppose it'll be in the next release...

  • Bob (unregistered) in reply to Richard T. Roll

    Applause!

  • PHPGangsta (unregistered)

    Last week I wrote code to display a drop-down-field for birthday, with the last 120 years (1890-2010). That was done with a few (~5 or so) lines of code.

    Would be interesting to see this in your notation. Great code example!

  • silent d (unregistered)

    I want to hear more about the OP's previous job, where business analysts wrote requirements to implement bugs.

  • Bob (unregistered) in reply to Voodoo Coder

    strtotime("-7 years") is pretty close.

  • Dirk (unregistered)

    Last post.

  • Dirk (unregistered)

    Last last post.

  • Dirk (unregistered)

    OK I'll stop now.

  • Slink (unregistered) in reply to grizz
    grizz:
    Richard T. Roll:
    I've used this a lot in my programming career and I know some might disagree but tbh it's just a different approach.

    I've used cannibalism a lot in my food-procuring career and I know some might disagree but tbh it's just a different approach.

    Sometimes "bad" really is bad, not just different.

    You were writing that as a reply to a post made by Richard T.Roll... Sarcasm detector offline? ;) Or am I the one missing that sarcasm tag in your reply?

  • Manniakk (unregistered)

    $TheDayBeforeTheFirstMondayOfThisMonthLastYear = "Sunday";

    sooo simple :D

  • (cs) in reply to jonsjava
    jonsjava:
    Anon:
    ... I mean, this is php after all.

    PHP isn't a bad scripting language. It's just that 99% of the PHP coders give the rest of us a bad name. I use it for server-side coding (both windows/linux) when I need a script to do something, and I don't have the time to build a real app. Handy little system in a pinch.

    Whenever i look at stats like "99% of php code is crap" i wonder - is it that 99% of the PHP programmers are crap, or that all php programmer are crappy 99% of the time?

  • (cs)

    ThisYear - 7 is not allowed as 7 is a magic number.

    LastLastLastLastLastLastLastYear is much better.

  • kftt (unregistered) in reply to me
    me:
    what are the odds that the probeility of the month being frebruary?
    smarch
  • (cs) in reply to jonsjava
    jonsjava:
    PHP isn't a bad scripting language.

    Yes it is. PHP is poorly designed and inconsistent. The most popular implementation is also a mess and unlikely to get better - one of the leading guys working on improving the stability and security of the code quit in disgust at the unwillingness of Zend to accept changes.

  • 1234 (unregistered) in reply to Dirk
    Dirk:
    OK I'll stop now.

    Thank you.

  • Marius (unregistered) in reply to PHPGangsta

    And did you have any 120 years old visitors on that site? I'm curious.

  • aBase (unregistered) in reply to jonsjava
    jonsjava:
    It's just that 99% of the PHP coders give the rest of us a bad name.
    Yeah, they're the ones who go around saying things like "99% of..."
  • (cs) in reply to toth
    toth:
    Paula Bean taught me that.
    Isn't she on the same network as Rachael Array?
  • Dascandy (unregistered) in reply to Cbuttius

    That's a comment that's so rational yet so wrong that my stomach contracted. I can imagine that actually being brought forward by somebody.

    That somebody wouldn't be my colleague for long, one way or another.

  • drive-by proofreader (unregistered)
    "When I took a new job at a small company, I knew the processes WOULD be a little more 'casual', but I never quite expected this. Even the code is written casually, avoiding unnecessary formalities like arrays and loops."
  • Enterprise Architect (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    PHP is poorly designed and inconsistent. The most popular implementation is also a mess and unlikely to get better - one of the leading guys working on improving the stability and security of the code quit in disgust at the unwillingness of Zend to accept changes.
    Aaah… the wonders of open source.

    http://qdb.us/301603

    To Akismet: Who spams by posting links to QDB?

  • forgottenlord (unregistered)
    When I took a new job at a small company, I knew the processes wouldn't be a little more 'casual', but I never quite expected this. Even the code is written casually,

    "Wouldn't be a little more 'casual'? But then....how is the code casual if it wouldn't be more casual? </pedantic-bastard>

  • (cs)

    Those names are going to get totally unwieldy after a while, because of their length. The programmer should have gone with:

    $thisyear=date("Y");
    $lastyear=date("Y")-1;
    $theyearbeforelastyear=date("Y")-2;
    $the2ndyearbeforelastyear=date("Y")-3;
    $the3rdyearbeforelastyear=date("Y")-4;
    $the4thyearbeforelastyear=date("Y")-5;
    $the5thyearbeforelastyear=date("Y")-6;
    $the6thyearbeforelastyear=date("Y")-7;
    

Leave a comment on “Last, Last, Last, Last, Last, Last, Last Year”

Log In or post as a guest

Replying to comment #:

« Return to Article