Wonky Code
More solutions for idle CPU time.
Submitted by phrax on Tue, 2004-11-02 15:17. Wonky CodeYesterday we had a great example of how to make sure your database isn't slacking off. Here's a example to make sure your web server keeps working hard too.
Also thanks to everybody who submitted a WTF. Keep them coming! :)
<?php
if( $_USER['uid'] > 1 )
    {
        $usermenu = new Template( $_CONF['path_layout'] );
        $usermenu->set_file( array( 'option' => 'useroption.thtml',
                                    'current' => 'useroption_off.thtml' ));
        $usermenu->set_var( 'site_url', $_CONF['site_url'] );
        $usermenu->set_var( 'layout_url', $_CONF['layout_url'] );
        <strong>$usermenu->set_var( 'block_name', str_replace( '_', '-', 'user_block' ));</strong>
        if( empty( $title ))
        {
            $title = DB_getItem( $_TABLES['blocks'], 'title', "name='user_block'" );
        }
    //....
?>
A function made up of WTFs...
Submitted by phrax on Mon, 2004-10-25 15:03. Wonky CodeProps 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
- $argvwill 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]);
}
?>


