php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chealer at gmail dot com
New email:
PHP Version: OS:

 

 [2012-05-24 01:04 UTC] chealer at gmail dot com
Description:
------------
As explained on http://ca.php.net/manual/en/control-structures.foreach.php :

Warning

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:
https://bugs.php.net/bug.php?id=29992
https://bugs.php.net/bug.php?id=40654
https://bugs.php.net/bug.php?id=47388
https://bugs.php.net/bug.php?id=49386
https://bugs.php.net/bug.php?id=50485
https://bugs.php.net/bug.php?id=54189

aharvey@php.net pointed out that this problem was already discussed (see https://bugs.php.net/bug.php?id=60024 ).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-24 01:46 UTC] laruence@php.net
this is more about a wrong usage, fix this will introduce a big bc break.
 [2012-05-24 11:25 UTC] cataphract@php.net
-Status: Open +Status: Duplicate
 [2012-05-24 11:25 UTC] cataphract@php.net
The proper venue for this discussion is the internals mailing list.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 13:01:29 2024 UTC