0000-00-00 or bust



  • So, at my job I get to work with the codebase from several different programmers. There are tons of WTFs in every source file, but sometimes one is so grand that you have to wonder about who made it.

    	if ($A_birth_year || $A_birth_month || $A_birth_day) {
    		if ($A_birth_year) { $Ab_year = $A_birth_year; } else { $Ab_year = "0000"; $Abirth_date_count++; }
    		if ($A_birth_month) { $Ab_month = $A_birth_month; } else { $Ab_month = "00"; $Abirth_date_count++; }
    		if ($A_birth_day) { $Ab_day = $A_birth_day; } else { $Ab_day = "00"; $Abirth_date_count++; }
    		if ($A_birth_date_count == 2) { 
    			if ($A_birth_year) { $A_birth_date = "$A_birth_year-00-00"; }
    			elseif ($A_birth_month) { $A_birth_date = "0000-$A_birth_month-00"; }
    			elseif ($A_birth_day) { $A_birth_date = ""; }
    		} else {
    			$A_birth_date = "$Ab_year"."-"."$Ab_month"."-"."$Ab_day";
    		}
    	}
    	if ($M_birth_year || $M_birth_month || $M_birth_day) {
    		if ($M_birth_year) { $Mb_year = $M_birth_year; } else { $Mb_year = "0000"; $Mbirth_date_count++; }
    		if ($M_birth_month) { $Mb_month = $M_birth_month; } else { $Mb_month = "00"; $Mbirth_date_count++; }
    		if ($M_birth_day) { $Mb_day = $M_birth_day; } else { $Mb_day = "00"; $Mbirth_date_count++; }
    		if ($M_birth_date_count == 2) { 
    			if ($M_birth_year) { $M_birth_date = "$M_birth_year-00-00"; }
    			elseif ($M_birth_month) { $M_birth_date = "0000-$M_birth_month-00"; }
    			elseif ($M_birth_day) { $M_birth_date = ""; }
    		} else {
    			$M_birth_date = "$Mb_year"."-"."$Mb_month"."-"."$Mb_day";
    		}
    	}
    	if ($F_birth_year || $F_birth_month || $F_birth_day) {
    		if ($F_birth_year) { $Fb_year = $F_birth_year; } else { $Fb_year = "0000"; $Fbirth_date_count++; }
    		if ($F_birth_month) { $Fb_month = $F_birth_month; } else { $Fb_month = "00"; $Fbirth_date_count++; }
    		if ($F_birth_day) { $Fb_day = $F_birth_day; } else { $Fb_day = "00"; $Fbirth_date_count++; }
    		if ($F_birth_date_count == 2) { 
    			if ($F_birth_year) { $F_birth_date = "$F_birth_year-00-00"; }
    			elseif ($F_birth_month) { $F_birth_date = "0000-$F_birth_month-00"; }
    			elseif ($F_birth_day) { $F_birth_date = ""; }
    		} else {
    			$F_birth_date = "$Fb_year"."-"."$Fb_month"."-"."$Fb_day";
    		}
    	}
    	if ($O_birth_year || $O_birth_month || $O_birth_day) {
    		if ($O_birth_year) { $Ob_year = $O_birth_year; } else { $Ob_year = "0000"; $Obirth_date_count++; }
    		if ($O_birth_month) { $Ob_month = $O_birth_month; } else { $Ob_month = "00"; $Obirth_date_count++; }
    		if ($O_birth_day) { $Ob_day = $O_birth_day; } else { $Ob_day = "00"; $Obirth_date_count++; }
    		if ($O_birth_date_count == 2) { 
    			if ($O_birth_year) { $O_birth_date = "$O_birth_year-00-00"; }
    			elseif ($O_birth_month) { $O_birth_date = "0000-$O_birth_month-00"; }
    			elseif ($O_birth_day) { $O_birth_date = ""; }
    		} else {
    			$O_birth_date = "$Ob_year"."-"."$Ob_month"."-"."$Ob_day";
    		}
    	}
    
    	if ($A_race_code1) {$A_race .= "$A_race_code1:";}
    	if ($A_race_code2) {$A_race .= "$A_race_code2:";}
    	if ($A_race_code3) {$A_race .= "$A_race_code3:";}
    	if ($A_race_code4) {$A_race .= "$A_race_code4:";}
    	if ($A_race_code5) {$A_race .= "$A_race_code5:";}
    	if ($A_race_code6) {$A_race .= "$A_race_code6:";}
    	if ($A_race_code7) {$A_race .= "$A_race_code7:";}
    	if ($A_race_code8) {$A_race .= "$A_race_code8:";}
    	if ($A_race_code9) {$A_race .= "$A_race_code9:";}
    	if ($A_race_code10) {$A_race .= "$A_race_code10:";}
    	if ($A_race_code11) {$A_race .= "$A_race_code11:";}
    	if ($A_race_code12) {$A_race .= "$A_race_code12:";}
    	if ($A_race_code13) {$A_race .= "$A_race_code13:";}
    	if ($A_race_code14) {$A_race .= "$A_race_code14:";}
    
    	if ($M_race_code1) {$M_race .= "$M_race_code1:";}
    	if ($M_race_code2) {$M_race .= "$M_race_code2:";}
    	if ($M_race_code3) {$M_race .= "$M_race_code3:";}
    	if ($M_race_code4) {$M_race .= "$M_race_code4:";}
    	if ($M_race_code5) {$M_race .= "$M_race_code5:";}
    	if ($M_race_code6) {$M_race .= "$M_race_code6:";}
    	if ($M_race_code7) {$M_race .= "$M_race_code7:";}
    	if ($M_race_code8) {$M_race .= "$M_race_code8:";}
    	if ($M_race_code9) {$M_race .= "$M_race_code9:";}
    	if ($M_race_code10) {$M_race .= "$M_race_code10:";}
    	if ($M_race_code11) {$M_race .= "$M_race_code11:";}
    	if ($M_race_code12) {$M_race .= "$M_race_code12:";}
    	if ($M_race_code13) {$M_race .= "$M_race_code13:";}
    	if ($M_race_code14) {$M_race .= "$M_race_code14:";}
    
    	if ($F_race_code1) {$F_race .= "$F_race_code1:";}
    	if ($F_race_code2) {$F_race .= "$F_race_code2:";}
    	if ($F_race_code3) {$F_race .= "$F_race_code3:";}
    	if ($F_race_code4) {$F_race .= "$F_race_code4:";}
    	if ($F_race_code5) {$F_race .= "$F_race_code5:";}
    	if ($F_race_code6) {$F_race .= "$F_race_code6:";}
    	if ($F_race_code7) {$F_race .= "$F_race_code7:";}
    	if ($F_race_code8) {$F_race .= "$F_race_code8:";}
    	if ($F_race_code9) {$F_race .= "$F_race_code9:";}
    	if ($F_race_code10) {$F_race .= "$F_race_code10:";}
    	if ($F_race_code11) {$F_race .= "$F_race_code11:";}
    	if ($F_race_code12) {$F_race .= "$F_race_code12:";}
    	if ($F_race_code13) {$F_race .= "$F_race_code13:";}
    	if ($F_race_code14) {$F_race .= "$F_race_code14:";}
    
    	if ($O_race_code1) {$O_race .= "$O_race_code1:";}
    	if ($O_race_code2) {$O_race .= "$O_race_code2:";}
    	if ($O_race_code3) {$O_race .= "$O_race_code3:";}
    	if ($O_race_code4) {$O_race .= "$O_race_code4:";}
    	if ($O_race_code5) {$O_race .= "$O_race_code5:";}
    	if ($O_race_code6) {$O_race .= "$O_race_code6:";}
    	if ($O_race_code7) {$O_race .= "$O_race_code7:";}
    	if ($O_race_code8) {$O_race .= "$O_race_code8:";}
    	if ($O_race_code9) {$O_race .= "$O_race_code9:";}
    	if ($O_race_code10) {$O_race .= "$O_race_code10:";}
    	if ($O_race_code11) {$O_race .= "$O_race_code11:";}
    	if ($O_race_code12) {$O_race .= "$O_race_code12:";}
    	if ($O_race_code13) {$O_race .= "$O_race_code13:";}
    	if ($O_race_code14) {$O_race .= "$O_race_code14:";}
    
    etc.. etc...
    

    My favorite is all the effort that goes in to making sure dates are in the format 0000-00-00 while completely overlooking any built in PHP functions that would do it.

    What's not pictured here is the 20 or so form values that are put directly into the database with no escaping, validation, etc.



  • My rule of thumb: if your variable name has to contain a sequential letter or number, you're doing it wrong.



  • @realmerlyn said:

    My rule of thumb: if your variable name has to contain a sequential letter or number, you're doing it wrong.

    I like it, that's a damn good rule.  I would however propose:

    @DaveK's corollary to realmerlyn's law: said:

    '2' can be OK, as long as you don't make a habit of it.

    Also, that title should be written:

    [color=black;text-decoration:blink]0000-00-00[/color] or bust

     



  • What's not pictured here is the 20 or so form values that are put directly into the database with no escaping, validation, etc.

    Pretty much standard PHP practice then!


Log in to reply
 

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