Bug #71756 [NEW]: Call-by-reference widens scope to uninvolved functions when used in switch

From: Date: Wed, 09 Mar 2016 14:16:55 +0000
Subject: Bug #71756 [NEW]: Call-by-reference widens scope to uninvolved functions when used in switch
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199701@lists.php.net to get a copy of this message
From: lang at six dot de Operating system: Linux 7afb14e6ee75 3.16.7-35-des PHP version: 7.0.4 Package: Variables related Bug Type: Bug Bug description:Call-by-reference widens scope to uninvolved functions when used in switch Description: ------------ Under very certain circumstances a call-by-reference gets out of bounds. A cascaded call of functions, where one of them has a call-by-reference in its parameters, a change to a copy of an hash gets unexpectedly overwritten outside of its scope. Key to this behaviour is the use of the switch-statement in the final function call. Additional Information: - casting the switch-parameter to string solves the problem - changing the switch into an if-statement also solves the problem Test script: --------------- <?php function a ($option) { b($option['bla']); c($option); var_dump($option); } function b (&$string) { $string = 'changed'; } function c ($option) { switch ($option['bla']) { case 'changed': $copy = $option; $copy['bla'] = 'copy'; break; } } a(array('bla' => 'fasel')); Expected result: ---------------- array(1) { ["bla"]=> string(4) "changed" } Actual result: -------------- array(1) { ["bla"]=> string(4) "copy" } -- Edit bug report at https://bugs.php.net/bug.php?id=71756&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71756&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71756&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71756&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71756&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71756&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71756&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71756&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71756&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71756&r=support Expected behavior: https://bugs.php.net/fix.php?id=71756&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71756&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71756&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71756&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71756&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71756&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71756&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71756&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71756&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71756&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71756&r=mysqlcfg

« previous php.bugs (#199701) next »