From:             lbayuk at pobox dot com
Operating system: Linux
PHP version:      5.2.1
PHP Bug Type:     Arrays related
Bug description:  Indexing non-array should raise notice

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 bug report at http://bugs.php.net/?id=41195&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41195&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41195&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41195&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41195&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41195&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41195&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41195&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41195&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41195&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41195&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41195&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41195&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41195&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41195&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41195&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41195&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41195&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41195&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41195&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41195&r=mysqlcfg

Reply via email to