Roger took on a contract to fix up a PHP website. During the negotiations, he asked some questions about the design, like, "Is it object-oriented or more procedural?" "No, it's PHP," said the developer.

Which about sums it up, I suppose. Have some date handling code:

function MnameToMnumber($mname) //takes month name 'January' and returns month number '01'
        {
        if($mname == 'January'){$mnum = '01';}
        elseif($mname == 'February'){$mnum = '02';}
        elseif($mname == 'March'){$mnum = '03';}
        elseif($mname == 'April'){$mnum = '04';}
        elseif($mname == 'May'){$mnum = '05';}
        elseif($mname == 'June'){$mnum = '06';}
        elseif($mname == 'July'){$mnum = '07';}
        elseif($mname == 'August'){$mnum = '08';}
        elseif($mname == 'September'){$mnum = '09';}
        elseif($mname == 'October'){$mnum = '10';}
        elseif($mname == 'November'){$mnum = '11';}
        elseif($mname == 'December'){$mnum = '12';}
        return $mnum;
        }

function MnumberToMname($mname) //takes month number '01' and returns month name '01'
        {
        if($mnum= '01'){$mname = 'January';}
        elseif($mnum= '02'){$mname = 'February';}
        elseif($mnum= '03'){$mname = 'March';}
        elseif($mname == 'April'){$mnum = '04';}
        elseif($mnum= '05'){$mname = 'May';}
        elseif($mnum= '06'){$mname = 'June';}
        elseif($mnum= '07'){$mname = 'July';}
        elseif($mnum= '08'){$mname = 'August';}
        elseif($mnum= '09'){$mname = 'September';}
        elseif($mnum= '10'){$mname = 'October';}
        elseif($mnum= '11'){$mname = 'November';}
        elseif($mnum= '12'){$mname = 'December';}
        return $mname;
        }

So, for starters, I "love" the use of Whitesmiths indenting. I don't think I've seen this in the wild. (I predict the comments section will be links to articles where I have seen this in the wild).

Beyond that, there's nothing terribly surprising here, in terms of bad date handling code, with a few small exceptions. First is their insistence on the conversion itself being stringly typed: January isn't month 1, but "01".

But more notable: MnumberToMname just doesn't work. They're using the assignment operator instead of the equality operator. At least, for all the cases where they're doing the correct comparison direction. A stray "name to number" conversion is lurking in April. Not that it matters- this will always return January.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.