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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 01:01:33 2025 UTC