Bug #54358 [Opn->Asn]: Closure, use and reference
| From: | pajoye@php.net | Date: | Wed, 23 Mar 2011 11:45:57 +0000 |
| Subject: | Bug #54358 [Opn->Asn]: Closure, use and reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159726@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54358&edit=1
ID: 54358
Updated by: pajoye@php.net
Reported by: frederic dot hardy at mageekbox dot net
Summary: Closure, use and reference
-Status: Open
+Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.3.6
-Assigned To:
+Assigned To: dmitry
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2011-03-23 11:03:37] frederic dot hardy at mageekbox dot net
Trunck version is not affected by this bug.
------------------------------------------------------------------------
[2011-03-23 10:56:19] frederic dot hardy at mageekbox dot net
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 this bug report at http://bugs.php.net/bug.php?id=54358&edit=1