php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60024 Do not keep last element treated by foreach referenced
Submitted: 2011-10-09 21:09 UTC Modified: 2012-02-07 02:38 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: chealer at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.3.8 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
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:

 

 [2011-10-09 21:09 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 situations causes bugs like https://bugs.php.net/bug.php?id=49386


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-06 00:47 UTC] DeveloperGuy2008 at yahoo dot com
Please fix this. It creates a lot of hard to debug bugs.
 [2012-02-06 00:53 UTC] aharvey@php.net
-Status: Open +Status: Duplicate
 [2012-02-06 00:53 UTC] aharvey@php.net
This has previously been discussed and rejected, due to users relying both on 
PHP's lack of block scope and foreach's by-reference syntax. (Sometimes both at 
once, unfortunately.)

Duplicate of bug #29992, bug #47388, bug #54189, bug #50485, and probably a bunch 
of others.
 [2012-02-06 22:24 UTC] chealer at gmail dot com
Could the discussion be linked to?

This is not a duplicate of any of the reports indicated. The reports indicated are reports of application bugs as PHP bugs, which are therefore invalid. This report is asking to change PHP, in order to avoid such application bugs.
 [2012-02-07 00:10 UTC] aharvey@php.net
Sure, it's come up on the mailing list a few times, but the one I was thinking of 
specifically is: http://comments.gmane.org/gmane.comp.php.devel/59471
 [2012-02-07 02:38 UTC] chealer at gmail dot com
Thank you. I read the discussion once, but I didn't see where it rejects this. Could the rejections be quoted or pointed more specifically?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 08:01:27 2024 UTC