Bug #72036 [NEW]: Reference parameters of functions fail to work properly in some cases
| From: | karl dot riedling at tuwien dot ac dot at | Date: | Sat, 16 Apr 2016 08:51:33 +0000 |
| Subject: | Bug #72036 [NEW]: Reference parameters of functions fail to work properly in some cases | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200585@lists.php.net to get a copy of this message | ||
From: karl dot riedling at tuwien dot ac dot at
Operating system: Linux 2.6.32-042stab
PHP version: 7.0.5
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Reference parameters of functions fail to work properly in some cases
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 bug report at https://bugs.php.net/bug.php?id=72036&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72036&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72036&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72036&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72036&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72036&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72036&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72036&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72036&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72036&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72036&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72036&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72036&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72036&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72036&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72036&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72036&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72036&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72036&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72036&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72036&r=mysqlcfg