October 18, 2007

PHP ghost array item at index 0

Here's a copy-paste that boiled me for some minutes today (in collaboration with PEAR's Mail and Mail_Mime, but it wasn't their fault):
$something = array(
'key1' => 'abracadabra',
'key2' => "Some longer string, {$somearray['somekey']}", $scalar,
);

All in all, there was a ghost item at $something's index 0. Yep, in my case above, $something[0] == $scalar.

So here's the lesson: if an item shows up at index 0 in a PHP array where you defined key=>value pairs, you probably have a value running loose somewhere in your definition...

0 comments:

Post a Comment