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
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.
Password:
Status:
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: Fri May 24 08:01:33 2024 UTC