php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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

Add a Patch

Pull Requests

Add a Pull Request

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
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=310050
Log: - Fixed bug #54358 (Closure, use and reference)
- Fixed bug #54039 (use() of static variables in lambda functions can break staticness)
 [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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC