From:             tony at marston-home dot demon dot co dot uk
Operating system: Windows XP
PHP version:      4.4.1
PHP Bug Type:     Arrays related
Bug description:  foreach nullifies index of an inexed array

Description:
------------
When I use foreach($array as $key => $value) on an indexed array,
afterwards the index value, when viewed with key($array) is null instead
of an integer. This means that when my code tests the array to see if it
is either indexed or associative it is given the wrong answer.

Reproduce code:
---------------
<?php
$array[] = 'string of data';

if (is_int(key($array))) {
        echo "array is indexed\n";
} else {
        echo "array is associativ\/n";
} // if

foreach ($array as $key => $value) {
    if ($key === key($array)) {
        echo "they are the same\n";
    } else {
        echo "they are NOT the same\n";
    } // if
} // foreach

if (is_int(key($array))) {
        echo "array is indexed\n";
} else {
        echo "array is associative\n";
} // if
?>

Expected result:
----------------
The output 'array is indexed' should be produced both before and after the
foreach() statement.

Actual result:
--------------
The key of an indexed array, when viewed with key($array), is not being
reported as an integer.

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

Reply via email to