From:             ben at bravenet dot com
Operating system: Ubuntu Hoary 5.04
PHP version:      4.3.10
PHP Bug Type:     Arrays related
Bug description:  key() returns an incorrect key after a foreach()

Description:
------------
After a foreach() on an array, key() won't return a value from the same
array.

It looks like an internal array pointer problem, since a reset() before
key() appears to fix it.

Reproduce code:
---------------
<?php

$foo = array('a'=>'1', 'b'=>'2', 'c'=>'3');

foreach($foo as $k=>$v)
{

        echo "$k=>$v\n";
        
}
// reset($foo); // this fixes the problem
echo key($foo);

?>



Expected result:
----------------
a=>1
b=>2
c=>3
a

Actual result:
--------------
a=>1
b=>2
c=>3



-- 
Edit bug report at http://bugs.php.net/?id=32959&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32959&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32959&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32959&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32959&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32959&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32959&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32959&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32959&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32959&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32959&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32959&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32959&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32959&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32959&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32959&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32959&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32959&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32959&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32959&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32959&r=mysqlcfg

Reply via email to