From: Operating system: PHP version: 5.3.6 Package: Scripting Engine problem Bug Type: Bug Bug description:Closure, use and reference
Description: ------------ When the same variable is 'used' by one closure by reference, and an another closure 'uses' the same variable by value several time, the variable value is corrupted. This bub seems to be related to http://bugs.php.net/53958 which is closed since PHP 5.3.6. Test script: --------------- <?php class asserter { public function call($function) {} } $asserter = new asserter(); $closure = function() use ($asserter, & $function) { $asserter->call($function = uniqid()); }; try { $closure(); } catch (\exception $exception) { } var_dump($function); $function = 'md5'; $closure = function() use ($asserter, $function) { $asserter->call($function); }; try { $closure(); } catch (\exception $exception) { } var_dump($function); $closure = function() use ($asserter, $function) { $asserter->call($function); }; try { $closure(); } catch (\exception $exception) {} var_dump($function); ?> Expected result: ---------------- string(13) "4d89c1bc241ff" string(3) "md5" string(3) "md5" Actual result: -------------- string(13) "4d89c1bc241ff" string(3) "md5" string(3) �a" -- Edit bug report at http://bugs.php.net/bug.php?id=54358&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54358&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54358&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54358&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54358&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54358&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54358&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54358&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54358&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54358&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54358&r=support Expected behavior: http://bugs.php.net/fix.php?id=54358&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54358&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54358&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54358&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54358&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54358&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54358&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54358&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54358&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54358&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54358&r=mysqlcfg