Some days I feel like I’m fighting with PHP every step (I’m sure most PHP programmers know what I mean). To stop it getting to me, I often try to come up creative ways to implement some code (often hacked up and unreadable) just to prove that I’m better than it is. :-)

The code below is used to transform rows from a database query, and has an ugly hack to work around a bug (atleast IMO) regarding the scope of functions created with `create_function`

$whoNeedsStructure = create_function('$r', 'global $__f; if(!isset($__f)) $__f = create_function(\'$m\', \'$r = DatabaseManager::get("bergamot")->query("SELECT * FROM record WHERE idDatabase IN (12,13,14) AND idPublic=?", array($m)); return $r[0]["id"];\'); return new Record580k($r["c"], $r["m"], $__f($r["m"]));');

// snip

return array_map($whoNeedsStructure, $rows)

Disclaimer: The script was a one off, and there is a comment that describes what the entire function is intended to do, so it’s not a complete maintenance nightmare.

Edit: Read post before pressing publish.