php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72108 switchs break foreach byref with arrays
Submitted: 2016-04-26 17:56 UTC Modified: 2016-04-26 19:20 UTC
From: php at darkain dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.5 OS: Debian 8.2
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: php at darkain dot com
New email:
PHP Version: OS:

 

 [2016-04-26 17:56 UTC] php at darkain dot com
Description:
------------
As shown in the test script, when a switch statement is used on a byref variable from a foreach, the reference is lost, and it changes to byval instead. 

This regression was introduced in 7.0.5, and worked perfectly otherwise in previous builds of 7.0.x, 5.6, and HHVM

https://3v4l.org/eg1oT

Test script:
---------------
$array = ['broken'];

foreach($array as &$values) {
	switch ($values) {
		case 'broken':
			$values = 'WORKING';
		break;
	}
}

var_dump($array);

Expected result:
----------------
array(1) {
  [0]=>
  &string(7) "WORKING"
}

Actual result:
--------------
array(1) {
  [0]=>
  string(6) "broken"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-26 17:57 UTC] cmb@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-04-26 19:20 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2016-04-26 19:20 UTC] requinix@php.net
Yet another duplicate of bug #71914.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC