From: sigge at hystrix dot se Operating system: PHP version: 5.0.4 PHP Bug Type: Strings related Bug description: $string["otherstring"] = something | should produce a warning
Description: ------------ I recently had a bug in my code that overwrote an array with a string. I missed the [], it happens. But debugging was hard, and I had a bunch of $array["foo"] = "bar"; when $array had been overwritten by a string. As kind people on #php explained to me, PHP treats any string as 0. While I can understand such behaviour, I think there should be a warning like "you are treating a string as an array" or something. This warning should probably not occur when the key is a number, as this would return the character, but when accessing a string key of a string makes no sense. I can't see how this would break any backward compatibility, and it would make debugging much easier! Edit: I've now seen that there are similar bugs, all marked closed and without any non-stock explanation. I would really like to know why this "is expected", because to me, having developed in PHP for two years, this wasn't expected at all, and caused me a good headache. Pardon me if I am spamming, I would prefer to add a comment to those bugs, but can't. Reproduce code: --------------- $array = array(); $array = "string"; $array["foo"] = "bar"; Expected result: ---------------- Would be nice if it produced a warning on line 3, "Trying to access a string as an array" -- Edit bug report at http://bugs.php.net/?id=33879&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33879&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33879&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33879&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33879&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33879&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33879&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33879&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33879&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33879&r=support Expected behavior: http://bugs.php.net/fix.php?id=33879&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33879&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33879&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33879&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33879&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33879&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33879&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33879&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33879&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33879&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33879&r=mysqlcfg