php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45135 reference problems
Submitted: 2008-05-30 08:51 UTC Modified: 2008-05-30 09:08 UTC
From: byraul at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.6 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: byraul at gmail dot com
New email:
PHP Version: OS:

 

 [2008-05-30 08:51 UTC] byraul at gmail dot com
Description:
------------
Reference problems

Reproduce code:
---------------
<?php
$matches = array(
    array('one0', 'two0', 'three0'),
    array('one1', 'two1', 'three1'),
    array('one2', 'two2', 'three2'),
    array('one3', 'two3', 'three3'),
    array('one4', 'two4', 'three4'),
);
foreach($matches as $key=>&$value)
{
}

foreach($matches as $value)
{
    echo $value[0] . PHP_EOL;
}

Expected result:
----------------
one0
one1
one2
one3
one4

Actual result:
--------------
one0
one1
one2
one3
one3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-30 09:04 UTC] felix dot devliegher at gmail dot com
This is not a bug, but expected behaviour. The last iteration of the 
foreach with reference value references itself, with a current value of 
'one3' at that point, thus saving one3 as last value.
 [2008-05-30 09:08 UTC] derick@php.net
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

As explained by Felix.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Nov 20 14:00:01 2025 UTC