The Daily WTF
Cassi continues the fight against ancient, creaky PHP code.
Today, it’s particularly ancient- according to source control, it predates PHP 5.0 (and thus structured exceptions, and in this case may predate the current century). So the fact that this sets a pass-by-reference $errMsg variable and returns false on an error isn’t the WTF in the code.
$infoPtr->mysqlName = $row[“mysqlName”]; if (!$infoPtr->mysqlName) { $errMsg = “No table named “” . $infoPtr->mysqlName .”””; return(false); }
The surrounding code supports dynamically generating queries (through string concatenation, naturally), but does its best to do some validation of those inputs. For example, it attempts to confirm that the table we’re about to query exists in the database.
So we read the data out of the $row in the database, and if the resulting value is false-y (we’d expect it to be empty), we want to generate an error message… using that empty value.
To read the full article click on the 'post' link at the top.