ID: 30885 User updated by: php-bug-2004 at ryandesign dot com Reported By: php-bug-2004 at ryandesign dot com Status: Open Bug Type: *General Issues Operating System: N/A PHP Version: 5.0.2 New Comment:
I'm sorry -- I just found the bug of which this one is a duplicate: http://bugs.php.net/bug.php?id=29271 But I am not satisfied with the resolution of that bug ("bogus"). The problem is that when I said $test['some string'] = '234' I _wanted_ to create an associative array -- and if $test had been undefined, that would have happened. But because $test was already a string, the behavior was different and undesired. The problem is that $test was expected to be undefined at that point in the code, but due to an unexpected set of circumstances actually turned out to be a string. The amount of debugging that was necessary to discover this mistake was non-trivial, and it could have been prevented if PHP had issued a warning. Previous Comments: ------------------------------------------------------------------------ [2004-11-24 19:01:18] php-bug-2004 at ryandesign dot com Description: ------------ Accessing a character of a string using the deprecated array notation when the array index is not a number does not produce a notice or warning, but I believe it should. If I write $test['some string'] = '234' what I probably want to do is to have $test be an array with a key 'some string' and a value '234', but if $test was already a string, PHP instead sets character index 0 of the string to "2". PHP should issue an error of some kind, alerting the programmer that $test is being used as a string, so that the programmer can properly initialize the array with $test = array() before filling it. Reproduce code: --------------- $test = 'blah'; $test[2] = 'x'; // sets the third character of $test to "x" echo $test . "<br />\n"; // outputs "blxh" $test['some string'] = '234'; // sets the first character of $test to "2" echo $test . "<br />\n"; // outputs "2lxh" Expected result: ---------------- Warning: invalid non-numeric index into string $test ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30885&edit=1