ID: 41195 User updated by: lbayuk at pobox dot com Reported By: lbayuk at pobox dot com Status: Open Bug Type: Feature/Change Request Operating System: Linux PHP Version: 5.2.1 New Comment:
OK, so we're back at Feature/Change Request. Except on further thought I like the way it works and would prefer it not change. I just want clarification of what is supposed to happen when you apply square brackets to a non-array. If it is working as intended (silenty returns NULL), please document it. If it isn't working as intended, please fix it. Previous Comments: ------------------------------------------------------------------------ [2007-05-02 10:35:40] [EMAIL PROTECTED] Change requests belong to the "Feature/Change Request" category. Reclassified. ------------------------------------------------------------------------ [2007-05-01 01:32:05] lbayuk at pobox dot com 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. ------------------------------------------------------------------------ [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