If empty...



  • First post here... i've been lurking for a while, but just now saw something so simple and at the same time so multi-WTFish that i can't control my urge to share. so enjoy:

    <?
    function if_empty($data) {
     if (empty($data))
      return false;
     else
      return true;
    }
    ?>



  • @bdew said:

    <?

    function if_empty($data) {
     if (empty($data))
      return false;
     else
      return true;
    }
    ?>

    Wow, way to turn one line of code into six and still not get it right.

    I'm going to assume that the switch of false and true is unintentional.  If it's intended, then the WTF is just the existence of this function and the function name.
     



  • I'd hate to see that code actually used:

    if(!if_empty($data)) // $data is empty

    if(if_empty($data)) // $data is not empty 

    runs away screaming
     



  • FWIW, that's actually a workaround to a PHP WTF.

    "empty()" in PHP is, as the manual says "a
    language construct and not a function", which means you can't use it in a lot of situations -- for instance, as a callback
    .  IIRC, "isset()" has similar issues.



  • @bdew said:

    First post here... i've been lurking for a while, but just now saw something so simple and at the same time so multi-WTFish that i can't control my urge to share. so enjoy:

    <?
    function if_empty($data) {
     if (empty($data))
      return false;
     else
      return true;
    }
    ?>

     

    YES! That was the function from my dream... I dreamed that someone(or some computer program) could tell me if something is empty without calling the empty function... 



  • Sorry... did you notice: if_empty returns false if something is empty and true if it is not...

     

    I could understand:

    function emptyWrapper($data){
        return empty($data);
    }
     



  • That's funny, I have my own version of if_empty. I like it better, but I could be biased!

    function if_empty($temp,$flippy)
    {
      global $flempty;
      $flempty = $flippy;
      return empty_schlempty($temp) ? false : true;
    }
    
    function empty_schlempty($tempy)
    {
      global $flempty;
      return $flempty ? empty($tempy) : !empty($tempy);
    }

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.