Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #35093 : foreach nullifies index of an inexed array
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 20th April 21:37
php-bugs
External User
 
Posts: 1
Default #35093 : foreach nullifies index of an inexed array


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 With Quote


  sponsored links


2 20th April 21:37
External User
 
Posts: 1
Default #35093 : foreach nullifies index of an inexed array


ID: 35093
Updated by: sniper@php.net
Reported By: tony at marston-home dot demon dot co dot uk
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows XP
PHP Version: 4.4.1
New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same.

Thank you for your interest in PHP.


Previous Comments:
------------------------------------------------------------------------

[2005-11-03 21:10:23] tony at marston-home dot demon dot co dot uk

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 this bug report at http://bugs.php.net/?id=35093&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666