I know it's my fault, but come on
Feb. 13th, 2008 09:58 amOnce again, the weak typing and checks of PHP drive me to the brink of insanity (or still farther past it, depending on your definitions). Consider the following: I am picking a random element from an array and returning it, optionally removing it, to tweak test parameters. The array is associative, so I need to return a pair of $key, $value. I whip out iteration #1 of the utility function, which just returns array($key => $value). Makes sense, right? Key => value. Now I go on with my main testing function:
$arr = array(...); list($key, $value) = $this->extractRandomArrayElement($arr); // $key is null??? // $value is null???
If you've been paying attention, you should be laughing at me (in my lame defence, I haven't had any coffee yet today). Of course the list construct assumes that I'm returning array($key, $value) while I'm returning array($key => $value)—a significant difference, and I'm trying to use list with two elements to extract a single-element array. (list is meant for numeric arrays, anyway.) Of course this code should fail. But it fails silently. The standard modus operandi for PHP when you do something completely nonsensical appears to be not to throw an exception and die (as Python would) or a fatal error and die (as PHP at least does on static syntax errors), but to assign null to everyone concerned and go on as though nothing had happened.
This is not helpful in the least.