|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67608 PHP Bug when reusing variables by references
Submitted: 2014-07-11 15:21 UTC Modified: 2014-07-11 17:00 UTC
From: rafavega at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.14 OS: Debian, MacOS
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: rafavega at gmail dot com
New email:
PHP Version: OS:


 [2014-07-11 15:21 UTC] rafavega at gmail dot com
What this code should do, is to take the $lines array and delete the 2B value, but it doesn’t work like that, and is because it get crash when you use the $items variable in the second foreach and you already used it as a referece variable, even if you clean the $items variable with an empty array as you see in the code.

Just if you change the name or the $items variable in the second foreach it works fine.

Test script:
$lines = array(
	'1' => array(
	'2' => array(

foreach($lines as &$items){
	foreach($items as $key => $value){
		if($value=='2B') unset($items[$key]);

$items = array();
foreach($lines as $key => $items){

Expected result:

Actual result:


add-fronk-support (last revision 2014-07-11 15:23 UTC by rafavega at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-11 17:00 UTC]
-Status: Open +Status: Not a bug
 [2014-07-11 17:00 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is unfortunate, but documented and expected behaviour.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 03:01:27 2024 UTC