Skip navigation.
Home

archives

A function made up of WTFs...

Wonky Code

Props to Alex @ thedailywtf.com for today's PHP WTF.

I'm rating this as a WTF because:

  1. The function only returns a NULL!
  2. It uses references to return values
  3. It pretty pointless, especially when you have $_GET
  4. It's doesn't really work
  5. $argv will always have just one element, unless you're running PHP as a shell script interpreter. Then maybe there would be more than 1 argument.
  6. $seperator[0] - WTF?! oh why!?
  7. It's just soooooo bad. This function is basically made up of different WTF's.

I hope this isn't used in production somewhere... <?php
/* joins argv into one string and then splits it into logical
elements (html formated)*/

function split_arguments($argv,$argc,&amp;$nr_arg,&amp;$args)
{
       
$str="";
       
$seperator = "&";
       for (
$i=0; $i&lt;$argc; $i++)
       {
               if (
$i==0) {
                       
$str = sprintf("%s",$argv[$i]);
               } else {
                       
$str = sprintf("%s %s",$str,$argv[$i]);
               }
       }
       
trim($str);
       for (
$i=0; $i&lt;strlen($str); $i++)
       {
               if (
$str[$i] == $seperator[0])
               {
                       
$nr_arg++;
               } else {
                       
$args[$nr_arg] .= $str[$i];
               }
       }
       unset(
$str);
       for (
$i=0; $i&lt;=$nr_arg; $i++)
       {
               
$args[$i] = rawurldecode($args[$i]);
       }
       return;
}
?>

I particularly love the way $str is concatenated! I've never seen it done like this before:

<?php
if ($i==0) {
        
$str = sprintf("%s",$argv[$i]);
} else {
        
$str = sprintf("%s %s",$str,$argv[$i]);
}
?>