ID:               24118
 Updated by:       [EMAIL PROTECTED]
 Reported By:      young at sl dot com dot ua
-Status:           Bogus
+Status:           Analyzed
-Bug Type:         Scripting Engine problem
+Bug Type:         Documentation problem
 Operating System: FreeBSD 4.7, Linux
 PHP Version:      4.3.2, 4.3.3-dev, 5.0.0-dev
 Assigned To:      zeev
 New Comment:

Make this a documentation problem..I couldn't find this explanation
there. :)



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

[2003-06-11 02:59:27] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Taking the reproducible example:

<?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>";
}
?>

You shouldn't be using the reference variable that you used previously
in the foreach loop, since every iteration will assign the value to
both $row, and any other references it's attached to, in this case,
$arr[4].  This is why you get the last iterated value ($arr[3]) in
$arr[4], when you get to it.



------------------------------------------------------------------------

[2003-06-10 18:15:29] [EMAIL PROTECTED]

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>

------------------------------------------------------------------------

[2003-06-10 17:56:08] [EMAIL PROTECTED]

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] [EMAIL PROTECTED]

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.


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/24118

-- 
Edit this bug report at http://bugs.php.net/?id=24118&edit=1


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to