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

Pull Requests

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 Dec 14 04:01:26 2024 UTC