A function made up of WTFs...
Props to Alex @ thedailywtf.com for today's PHP WTF.
I'm rating this as a WTF because:
- The function only returns a NULL!
- It uses references to return values
- It pretty pointless, especially when you have
$_GET
- It's doesn't really work
$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.$seperator[0]
- WTF?! oh why!?- 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,&$nr_arg,&$args)
{
$str="";
$seperator = "&";
for ($i=0; $i<$argc; $i++)
{
if ($i==0) {
$str = sprintf("%s",$argv[$i]);
} else {
$str = sprintf("%s %s",$str,$argv[$i]);
}
}
trim($str);
for ($i=0; $i<strlen($str); $i++)
{
if ($str[$i] == $seperator[0])
{
$nr_arg++;
} else {
$args[$nr_arg] .= $str[$i];
}
}
unset($str);
for ($i=0; $i<=$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]);
}
?>