#24118 [Asn]: Error while using foreach
| From: | elmicha@php.net | Date: | Tue, 10 Jun 2003 23:15:30 +0000 |
| Subject: | #24118 [Asn]: Error while using foreach | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-41643@lists.php.net to get a copy of this message | ||
ID: 24118
Updated by: elmicha@php.net
Reported By: young at sl dot com dot ua
Status: Assigned
Bug Type: Scripting Engine problem
-Operating System: FreeBSD 4.7
+Operating System: FreeBSD 4.7, Linux
-PHP Version: 4.3.3-dev, 5.0.0-dev
+PHP Version: 4.3.2, 4.3.3-dev, 5.0.0-dev
Assigned To: zeev
New Comment:
Yes; more evidence:
<?php
$arr = array(1, 2, 3, 4, 5);
$sizeOf = sizeof($arr);
for ($i = 0; $i < $sizeOf; $i++) {
$row = &$arr[$i];
}
foreach ($arr as $row) {
echo $row."<br>";
}
?>
Output: 1<br>2<br>3<br>4<br>4<br>
<?php
$arr = array(1, 2, 3, 4, 5);
$sizeOf = sizeof($arr);
for ($i = 0; $i < $sizeOf; $i++) {
$row = &$arr[$i];
}
foreach ($arr as $x) {
echo $x."<br>";
}
?>
Output: 1<br>2<br>3<br>4<br>5<br>
Previous Comments:
------------------------------------------------------------------------
[2003-06-10 17:56:08] sniper@php.net
Zeev, here is first one I verified with both 4.3.3-dev and 5.0.0-dev.
Have fun fixing this one. :)
------------------------------------------------------------------------
[2003-06-10 17:32:00] young at sl dot com dot ua
Sample code to make this bug:
<?php
$arr = array(1, 2, 3, 4, 5);
$sizeOf = sizeof($arr);
for ($i = 0; $i < $sizeOf; $i++) {
$row =& $arr[$i];
$row = $row * $row;
}
foreach ($arr as $row) {
echo $row."<br>";
}
?>
Return
1
4
9
16
16
------------------------------------------------------------------------
[2003-06-10 17:24:46] elmicha@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2003-06-10 17:20:10] young at sl dot com dot ua
Source code N1:
-----
foreach ($sqldata as $row) {
$item = $row;
print_r($item);
}
-----
Result 1:
Array
(
[DURATION] => 7
)
Array
(
[DURATION] => 230
)
Array
(
[DURATION] => 230
)
-----
Source code 2:
-----
foreach ($sqldata as $item) {
print_r($item);
}
-----
Result 2:
-----
Array
(
[DURATION] => 7
)
Array
(
[DURATION] => 230
)
Array
(
[DURATION] => 50
)
------
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24118&edit=1