|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81228 print_r incorrectly linked to pass by reference loop
Submitted: 2021-07-06 19:25 UTC Modified: 2021-07-06 20:59 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: manuel at m-arzberger dot de Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.4.21 OS: Ubuntu 20.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: manuel at m-arzberger dot de
New email:
PHP Version: OS:


 [2021-07-06 19:25 UTC] manuel at m-arzberger dot de
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:

$array = array('one', 'two', 'three', 'four');

foreach($array as &$value) { }
foreach($array as $value) { }


Expected result:
    [0] => one
    [1] => two
    [2] => three
    [3] => four

Actual result:
    [0] => one
    [1] => two
    [2] => three
    [3] => three


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-06 20:59 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-07-06 20:59 UTC]
See the warning box in the docs: <>.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 21 11:03:43 2023 UTC