From: php-bug-2004 at ryandesign dot com Operating system: N/A PHP version: 5.0.2 PHP Bug Type: *General Issues Bug description: Accessing string characters with dubious array indexes
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 bug report at http://bugs.php.net/?id=30885&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30885&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30885&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30885&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30885&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30885&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30885&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30885&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30885&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30885&r=support Expected behavior: http://bugs.php.net/fix.php?id=30885&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30885&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30885&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30885&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30885&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30885&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30885&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30885&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30885&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30885&r=mysqlcfg