PHP :: Bug #54358 :: Closure, use and reference

Bug #54358 Closure, use and reference
Submitted: 2011-03-23 10:56 UTC Modified: 2011-04-08 12:02 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: frederic dot hardy at mageekbox dot net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None

 [2011-03-23 10:56 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2011-03-23 11:03 UTC] frederic dot hardy at mageekbox dot net

Trunck version is not affected by this bug.

 [2011-03-23 12:45 UTC] pajoye@php.net

-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry

 [2011-04-08 12:02 UTC] dmitry@php.net

-Status: Assigned +Status: Closed

 [2011-04-08 12:02 UTC] dmitry@php.net

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.