|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 09:01:28 2024 UTC