From: ninzya at inbox dot lv Operating system: Windows 7 PHP version: 5.3.1RC4 PHP Bug Type: Scripting Engine problem Bug description: References passed to closures as variables corrupt original passed variable
Description: ------------ See the reproduce code. I have a variable $ref, which is a reference to another variable. I am passing $ref to closure as use() by value, but, this kind of passing corrupts $ref variable after definition of closure and $ref becomes no longer reference, but points directly to copied data of $source variable, which $ref was previously referring to. However, if i define closure the following way: $closure =function() use( &$ref) {// note pass-by-reference echo $ref; }; the $ref does not loose it's state. Reproduce code: --------------- $source ='Dmitry'; $ref =&$source; $closure =function() use( $ref) { echo $ref; }; $ref ='Dmitry2'; echo $ref ."\n"; echo $source ."\n"; Expected result: ---------------- Dmitry2 Dmitry2 Actual result: -------------- Dmitry2 Dmitry -- Edit bug report at http://bugs.php.net/?id=50230&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50230&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50230&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50230&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50230&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50230&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50230&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50230&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50230&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50230&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50230&r=support Expected behavior: http://bugs.php.net/fix.php?id=50230&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50230&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50230&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50230&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50230&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50230&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50230&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50230&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50230&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50230&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50230&r=mysqlcfg