Bug #72036 [Opn->Dup]: Reference parameters of functions fail to work properly in some cases
| From: | bwoebi@php.net | Date: | Sat, 16 Apr 2016 13:39:36 +0000 |
| Subject: | Bug #72036 [Opn->Dup]: Reference parameters of functions fail to work properly in some cases | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200591@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72036&edit=1
ID: 72036
Updated by: bwoebi@php.net
Reported by: karl dot riedling at tuwien dot ac dot at
Summary: Reference parameters of functions fail to work
properly in some cases
-Status: Open
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 2.6.32-042stab
PHP Version: 7.0.5
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #71914.
Previous Comments:
------------------------------------------------------------------------
[2016-04-16 08:51:30] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72036&edit=1