Friday, March 21, 2008

The worst block of PHP code.... ever.

Today, I was working on an integration project which we'll call "Project X". We've been working with this vendor, "Vendor X" for over a year now on integrating our site with theirs for a particular purpose (if you didn't notice I'm being intentionally vague) as not to violate slander laws.

This company just plain sucks.

Their hiring processing must involve questions like: "Have you heard of a computer before?", "Do you know how to spell your own name?"

Ok, I may be exaggerating, a _little_ bit... but you get the point; they are really really crappy.

So they have this software that we have to integrate with which is insanely bad in so many ways that I just can't go into without plain out giving away who they are. HOWEVER, I can show you a somewhat anonymous block of code which highlights the level of skill these "developers" employ.

So here you have it; the worst block of PHP code every written (for a production system that runs thousands of websites)


for ( ; $row = mysql_fetch_row($si); $string = ''):

foreach ($row as $k => $v):
if ($row[0] != $previous[0])
unset($previous);
if ($v && $k && $k < 9 && $previous[$k+4] != $row[$k+4]):
for ($x=0; $x < $k; $x++)
$string = sprintf("%s  ", $string);
$string = sprintf("%s%s
", $string, str_func($v));
endif;
endforeach;

unset($previous);
$previous = $row;

if ($row[0] == SOME_CONSTANT)
if ($row[1] != $param):
$anon_str .= ($anon_str ? $sep_str : '') . $string;
$param = $row[1];
else:
$anon_str .= $string;
endif;
else
if ($row[1] != $param):
$cat_str .= ($cat_str ? $sep_str : '') . $string;
$param = $row[1];
else:
$cat_str .= $string;
endif;
endfor;