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

Reply via email to