Funny code piece 1

A bit of things that i found funny.
We have method’s param with empty array default value and at first look we expect array here, but in fact it is can be a string with delimiter that we try transform to the array.

function SetHeader($Harray = [], $side = '', $write = false)
{
	$oddhtml = '';
	$evenhtml = '';
	if (is_string($Harray)) {
		if (strlen($Harray) === 0) {
			$oddhtml = '';
			$evenhtml = '';
		} elseif (strpos($Harray, '|') !== false) {
			$hdet = explode('|', $Harray);

I sure it is a lot of reasons for such code, backward compatibility obviously, but it still funny. Especially when you work a lot with legacy code and try improve that and when you show this as a joke some familiar developer and he answer: “Whats wrong? I do much more worst things in my projects!” :D.

What it is about

Its about my thoughts on legacy projects. Anyone can add more new legacy code in project that full of old legacy code
and thinking at same time: “Well, now i understand that i shouldn’t have done that. In my new project i will avoid such mistakes!”

But what about reverse this process, rewrite legacy code in something less painful and don’t add new legacy code?

It is interesting and valuable goal – transform legacy and sometimes facepalm-like project to something that easy to
support and implement new business logic for new real-world business rules.