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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 - 8 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 18 19:01:30 2024 UTC