In PHP, you can access characters in a string with the array syntax:
$foo = 'abc';
echo $foo[2]; // echos 'c'
I recently spent way too long debugging why $foo['id'] wasn’t giving me the expected result. It turned out that $foo was a string instead of an associative array. PHP seemed to be casting 'id' to the integer 0, without giving any notice:
$foo = 'abc';
echo $foo['id']; // echos 'a', without notice
PHP throws a nice warning when you do this with real arrays:
$foo = array('a', 'b', 'c');
$echo $foo['id']; // Notice: Undefined index: id in php shell code on line 1
How can I make (or why can’t) PHP throw an “Undefined index” notice instead of casting a string index to 0?
Unfortunately, there’s nothing you can do, short of patching PHP.
However, if you do want to patch PHP, this is a possible patch (against trunk):
Then: