Bug #54358 [Com]: Closure, use and reference
| From: | frederic dot hardy at mageekbox dot net | Date: | Wed, 23 Mar 2011 10:03:37 +0000 |
| Subject: | Bug #54358 [Com]: Closure, use and reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159725@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
Comment by: frederic dot hardy at mageekbox dot net
Reported by: frederic dot hardy at mageekbox dot net
Summary: Closure, use and reference
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Trunck version is not affected by this bug.
Previous Comments:
------------------------------------------------------------------------
[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