Bug #72817 [NEW]: array null index silently casts to empty string

From: Date: Thu, 11 Aug 2016 20:39:20 +0000
Subject: Bug #72817 [NEW]: array null index silently casts to empty string
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203196@lists.php.net to get a copy of this message
From: php at abiusx dot com Operating system: OS X 10.11 PHP version: 7.0.9 Package: Variables related Bug Type: Bug Bug description:array null index silently casts to empty string Description: ------------ Accessing an array will a null index is equal to accessing it with an empty string index, which is non-trivial and cause of many errors in applications. When a developer writes $a[$index]=5; They typically expect $index to be an index (regardless of type) and not null. But if it is null, the command still works and is equal to: $a[""]=5; //same as $a[null]=5; There is no trivial reason why null should cast to empty string, rather than say 0 or any other equivalent form. And this behavior typically should cause warnings or notices (although it breaks BC). Test script: --------------- $a=[]; $a[]=4; $a[null]=5; $a[]=6; var_dump($a); Expected result: ---------------- E_NOTICE, E_WARNING or $a[0]=5, but not $a[""]=5 Actual result: -------------- array(4) { [0]=> int(4) [""]=> int(5) [1]=> int(6) [2]=> int(7) } -- Edit bug report at https://bugs.php.net/bug.php?id=72817&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72817&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72817&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72817&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72817&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72817&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72817&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72817&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72817&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72817&r=support Expected behavior: https://bugs.php.net/fix.php?id=72817&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72817&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72817&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72817&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72817&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72817&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72817&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72817&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72817&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72817&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72817&r=mysqlcfg

« previous php.bugs (#203196) next »