The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

A new way of array checking in PHP

Last post 01-16-2007 12:25 PM by timmeh. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 01-10-2007 10:06 AM

    • dawguk
    • Not Ranked
    • Joined on 01-10-2007
    • Posts 1

    A new way of array checking in PHP

    This code is lifted from a socket handling class that I've been asked to work on today. Prepare to cringe: 

    if (eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 392',$v[0])) {
        return false;
    }

    It's worth noting that the foreach() statement will move from line 392 with so much as a return key (as it did today...). It's also worth noting that the path information is gloriously hard-coded. This was deemed dailywtf worthy in the office, and as such I present it to you now.

    Happy Wednesday :)

  • 01-10-2007 10:51 AM In reply to

    Re: A new way of array checking in PHP

    that is a big WTF, there are LOTS better ways to do this
  • 01-10-2007 11:13 AM In reply to

    Re: A new way of array checking in PHP

    Awesome!
  • 01-10-2007 12:59 PM In reply to

    Re: A new way of array checking in PHP

    You could wrap your foreach in an if(is_array($var))...

    Or... this.



     

  • 01-10-2007 1:16 PM In reply to

    • wgh
    • Top 500 Contributor
    • Joined on 07-07-2006
    • Posts 58

    Re: A new way of array checking in PHP

    dawguk:

    It's worth noting that the foreach() statement will move from line 392 with so much as a return key (as it did today...).

    What a silly oversight, when

    if (eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 392',$v[0]) || eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 393',$v[0]) || eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 394',$v[0]) || eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 395',$v[0]))

    would have enhanced future maintainability by at least 4%.

    "You can't triple-stamp a double-stamp."
  • 01-10-2007 2:01 PM In reply to

    • utoxin
    • Not Ranked
    • Joined on 11-24-2004
    • Springville, UT
    • Posts 16

    Re: A new way of array checking in PHP

    Wow. It's no wonder PHP gets a bad name. That's just horrible. And I'm a PHP developer. I've written a few kludges in my time, but I'm quite certain I never wrote anything /that/ bad.

     

  • 01-10-2007 2:09 PM In reply to

    • Pap
    • Top 150 Contributor
    • Joined on 09-12-2006
    • Earf
    • Posts 281

    Re: A new way of array checking in PHP

    You should really be printing the array using printer_write() to a wooden table, scanning it....
  • 01-10-2007 6:29 PM In reply to

    Re: A new way of array checking in PHP

    dawguk:

    This code is lifted from a socket handling class that I've been asked to work on today. Prepare to cringe: 

    if (eregi('Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 392',$v[0])) {
        return false;
    }

    It's worth noting that the foreach() statement will move from line 392 with so much as a return key (as it did today...). It's also worth noting that the path information is gloriously hard-coded. This was deemed dailywtf worthy in the office, and as such I present it to you now.

    Happy Wednesday :)

    Okay, this is the first time I've lol'd at this site in a very long time. You are an internet hero. 

  • 01-10-2007 8:08 PM In reply to

    Re: A new way of array checking in PHP

    wow.... simply wow... this one also caused me to not only lol but also made finally sign up for an account here (been reading for months) to slander the schmuck who put that in place.

     doesn't he know that a "strpos(Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 392) === false" if statement is faster!!!

    *sigh* idiot

     ;)
     

  • 01-11-2007 8:48 AM In reply to

    Re: A new way of array checking in PHP

    @chadillac 

    Careful, this guy might have some sort of developmental diplomatic immunity. 

    Anyway, surely allowing elementary language errors to simply escape down the socket or whatever for the client to puzzle out rather than handling it locally is just is a masterpiece of load balancing? :-P

    You lot are just jealous of the greater design here.

  • 01-12-2007 7:00 AM In reply to

    Re: A new way of array checking in PHP

    chadillac:

    doesn't he know that a "strpos(Invalid argument supplied for foreach() in /usr/cvs/projects/13xx/1371/Classes/XML/XML_inc.php on line 392) === false" if statement is faster!!!

     But, but ... regular expressions are COOL!
     

  • 01-12-2007 6:22 PM In reply to

    • RevEng
    • Top 500 Contributor
    • Joined on 03-03-2006
    • Saskatchewan, Canada
    • Posts 101

    Re: A new way of array checking in PHP

    What really makes me wonder, is that this error message is normally contained in an exception and is only visible in the output if it's not caught.  How did this exception end up in text form that the developer felt he needed to match?  He executed a separate page and let the next page check for an error message in the output? *faint*
    The reasonable man adapts himself to the world. The unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --GEORGE BERNARD SHAW, Maxims for Revolutionists
  • 01-12-2007 6:38 PM In reply to

    • Tweenk
    • Top 500 Contributor
    • Joined on 08-12-2006
    • Poland, Warsaw
    • Posts 92

    Re: A new way of array checking in PHP

    (drops jaw)

    (after a while of consternation, picks it up from the floor)

    Wow.

    1. eregi used to match a static string
    2. eregi used instead of preg
    3. hardcoded path
    4. hardcoded line number of a part of code in _another script_
    5. relying on the particular pattern of error reporting

    If this isn't worth the main page, I don't know what is.

    BTW, the path should be /usr/cvs/projects/13xx/1337/... LOL

  • 01-16-2007 12:25 PM In reply to

    • timmeh
    • Not Ranked
    • Joined on 01-16-2007
    • Posts 1

    Re: A new way of array checking in PHP

    Of course, you are assuming that the path also never changes as well, especially as this looks like it has come out of CVS.....
Page 1 of 1 (14 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems