php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42415 Key element cannot be a reference
Submitted: 2007-08-24 13:54 UTC Modified: 2014-12-31 16:28 UTC
Votes:11
Avg. Score:4.3 ± 0.9
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:3 (37.5%)
From: romaneos at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5CVS-2007-08-24 (CVS) OS: Windows
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: romaneos at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-24 13:54 UTC] romaneos at gmail dot com
Description:
------------
Fatal error:  Key element cannot be a reference



Reproduce code:
---------------
foreach($list as &$key=>&$value) {
    $key = $key+1;
    $value = $value+1;
}

This code will generate error:

    Fatal error:  Key element cannot be a reference



Expected result:
----------------
$list = array(1 => 2, 5 => 6);
foreach($list as &$key=>&$value) {
    $key = $key+1;
    $value = $value+1;
}


Expected result:

$list == array (
                2 => 3,
                6 => 7
               )

Actual result:
--------------
Fatal error:  Key element cannot be a reference


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-26 23:21 UTC] judas dot iscariote at gmail dot com
This is the expected behaviuor. the engine is just warning you that you are writting bad code.
 [2014-12-31 16:28 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2014-12-31 16:28 UTC] nikic@php.net
Marking as Wfx as this feature request is simply not feasible from a technical point of view.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 03:01:29 2024 UTC