Bug #81228 [Opn->Nab]: print_r incorrectly linked to pass by reference loop
| From: | cmb@php.net | Date: | Tue, 06 Jul 2021 20:59:48 +0000 |
| Subject: | Bug #81228 [Opn->Nab]: print_r incorrectly linked to pass by reference loop | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234844@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81228&edit=1
ID: 81228
Updated by: cmb@php.net
Reported by: manuel at m-arzberger dot de
Summary: print_r incorrectly linked to pass by reference loop
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Ubuntu 20.04
PHP Version: 7.4.21
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
See the warning box in the docs: <https://www.php.net/manual/en/control-structures.foreach.php>.
Previous Comments:
------------------------------------------------------------------------
[2021-07-06 19:25:34] manuel at m-arzberger dot de
Description:
------------
I'm using PHP 7.4.21 on Ubuntu 20.04
When you loop through an array the first time with pass by reference and then do it again without
passing by reference, print_r will return unexpected values. The last item of the array will not be
displayed, but the second to last.
The array shouldn't be linked in any way to the pass be reference loop at the point.
Test script:
---------------
<?php
$array = array('one', 'two', 'three', 'four');
foreach($array as &$value) { }
foreach($array as $value) { }
print_r($array);
Expected result:
----------------
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
Actual result:
--------------
Array
(
[0] => one
[1] => two
[2] => three
[3] => three
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81228&edit=1