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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 01:01:29 2024 UTC