|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62132 Do not keep last element treated by foreach referenced
Submitted: 2012-05-24 01:04 UTC Modified: 2012-05-24 11:25 UTC
From: chealer at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.4.3 OS:
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: chealer at gmail dot com
New email:
PHP Version: OS:


 [2012-05-24 01:04 UTC] chealer at gmail dot com
As explained on :


Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().

In my opinion, PHP shouldn't keep the last element referenced by default, but at least, please provide a syntax which will not keep it. The current situation causes bugs like: pointed out that this problem was already discussed (see ).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-24 01:46 UTC]
this is more about a wrong usage, fix this will introduce a big bc break.
 [2012-05-24 11:25 UTC]
-Status: Open +Status: Duplicate
 [2012-05-24 11:25 UTC]
The proper venue for this discussion is the internals mailing list.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC