#41195 [Opn]: Indexing non-array should raise notice
| From: | tony2001@php.net | Date: | Wed, 02 May 2007 10:35:41 +0000 |
| Subject: | #41195 [Opn]: Indexing non-array should raise notice | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-112167@lists.php.net to get a copy of this message | ||
ID: 41195
Updated by: tony2001@php.net
Reported By: lbayuk at pobox dot com
Status: Open
-Bug Type: Arrays related
+Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.2.1
New Comment:
Change requests belong to the "Feature/Change Request" category.
Reclassified.
Previous Comments:
------------------------------------------------------------------------
[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