ID: 41195 User updated by: lbayuk at pobox dot com Reported By: lbayuk at pobox dot com Status: Open -Bug Type: Feature/Change Request +Bug Type: Arrays related Operating System: Linux PHP Version: 5.2.1 New Comment:
Changed category... I thought I put it in as "Arrays related", but I guess I missed and it ended up as "Feature/Change Request". To me, this is either a bug, or a documentation improvement request, not a feature request. Previous Comments: ------------------------------------------------------------------------ [2007-04-26 01:38:31] lbayuk at pobox dot com Description: ------------ If I index a scalar or NULL variable as if it were an array, I get NULL back with no warning or notice. This is true for any index value, including 0. I expected an Undefined offset or incorrect type message. The manual says an integer variable = n will convert to array(0=>$n); that works on casting to array but not on indexing. Reproduce code: --------------- <?php error_reporting(E_ALL+E_STRICT); $arry = array(1=>1); $notarry = NULL; $intvar = 123; echo "1. arry[1] = " . $arry[1] . "\n"; echo "2. arry[2] = " . $arry[2] . "\n"; echo "3. intvar[0] = " . $intvar[0] . "\n"; echo "4. intvar[1] = " . $intvar[1] . "\n"; echo "5. notarry[1] = " . $notarry[1] . "\n"; Expected result: ---------------- "Notice: Undefined offset" (or incorrect type) for (2), (3), (4), and (5). Or maybe (3) should echo "123" via implicit cast. But only (2) raises a Notice; the others just echo NULL. Actual result: -------------- 1. arry[1] = 1 Notice: Undefined offset: 2 in /a5/home/ljb/lang/php/p.php on line 7 2. arry[2] = 3. intvar[0] = 4. intvar[1] = 5. notarry[1] = ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41195&edit=1