From: herve dot pages at laposte dot net Operating system: Fedorac Core 3 PHP version: 4.4.0 PHP Bug Type: Feature/Change Request Bug description: No warning for $a['zz'] if $a is not an assoc array
Description: ------------ PHP doesn't output any warning for $a['zz'] if $a is not an assoc array. This problem has been reported in Bug #33879 in the particular case where $a is a string. Since individual chars in a string can be accessed using the $a[] syntax, and since the key 'zz' will be automatically cast to 0, then I can understand why PHP will accept $a['zz'] without complaining. But when $a is an integer, or a bool, or anything else that has nothing to do with an array (or a string), I don't see any reason why PHP should accept $a['zz'] without complaining! It would make some bugs much easier to find... Reproduce code: --------------- <?php error_reporting(E_ALL); $assoc = array(); $test = $assoc['zz']; // Warning "Undefined index: zz..." issued. OK // Now what if the $assoc variable is replaced by a variable that is not // an assoc array? // The expected/natural behaviour would be that PHP complains even // stronger because if such situation were occuring with a compiled // language, any descent compiler would not even compile. $not_an_assoc = 85; $test = $not_an_assoc['zz']; // No warning issued! echo gettype($test); // -> Display NULL $not_an_assoc = "85"; $test = $not_an_assoc['zz']; // No warning issued! echo $test; // -> Display 8 ?> Expected result: ---------------- It would be nice if PHP could tell me I'm doing something wrong with a warning or an error (that's why I'm using error_reporting(E_ALL) after all). -- Edit bug report at http://bugs.php.net/?id=34341&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34341&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34341&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34341&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34341&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34341&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34341&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34341&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34341&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34341&r=support Expected behavior: http://bugs.php.net/fix.php?id=34341&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34341&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34341&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34341&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34341&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34341&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34341&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34341&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34341&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34341&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34341&r=mysqlcfg