php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72036 Reference parameters of functions fail to work properly in some cases
Submitted: 2016-04-16 08:51 UTC Modified: 2016-04-16 13:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: karl dot riedling at tuwien dot ac dot at Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.5 OS: Linux 2.6.32-042stab
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: karl dot riedling at tuwien dot ac dot at
New email:
PHP Version: OS:

 

 [2016-04-16 08:51 UTC] karl dot riedling at tuwien dot ac dot at
Description:
------------
Functions with reference parameters that modify the value of the parameter within a switch() construct return the original value of the reference parameter rather than the modified one. This does not apply if the reference parameter is changed in an if() statement or in plain linear code; PHP 7.0.5 shows the expected behavior in these cases. This problem newly appeared with PHP 7.0.5. The test script below returns with PHP 7.0.4:

PHP Version: 7.0.4
23:12:25
Before function call: 1
In function call: 2
After function call: 2

Bug with PHP 7.0.5:

PHP Version: 7.0.5
21:14:06
Before function call: 1
In function call: 2
After function call: 1


Test script:
---------------
function test_func (& $x) {
	switch ($x) {
		case 1:
			$x = 2;
			break;
		case 2:
			break;
	}
	echo "In function call: ".$x."<br>\n";
}

$x = 1;
echo date ("H:i:s")."<br>\n";
echo "Before function call: ".$x."<br>\n";
test_func ($x);
echo "After function call: ".$x."<br>\n";


Expected result:
----------------
Before function call: 1
In function call: 2
After function call: 2

Actual result:
--------------
Before function call: 1
In function call: 2
After function call: 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-16 13:39 UTC] bwoebi@php.net
-Status: Open +Status: Duplicate
 [2016-04-16 13:39 UTC] bwoebi@php.net
Duplicate of bug #71914.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC