Edit report at https://bugs.php.net/bug.php?id=62452&edit=1

 ID:                 62452
 Comment by:         hanskrentel at yahoo dot de
 Reported by:        hanskrentel at yahoo dot de
 Summary:            Variable Aliasing does not work in Closure
 Status:             Wont fix
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Multiple
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

hi @laurence, thank's for taking the time to review it. If I write code like

unset($this);

it does not fatal error either (you can not destroy a object while you are 
calling 
it.).

Also I don't want to destroy the closure, I just want to re-use that variable. 
Can't you just let the garbage collector do the dirty work?


Previous Comments:
------------------------------------------------------------------------
[2012-07-02 07:03:19] larue...@php.net

you can not destroy a closure while you are calling it.

when you override $f in $f, zend vm try to destroy the closure $f, since the 
refcout of it is 1.

try following :

$b = $f = function() use (&$f) {
    $f = function() {};
};
$f();
$f();

------------------------------------------------------------------------
[2012-06-29 20:05:06] ni...@php.net

Verified on master.

------------------------------------------------------------------------
[2012-06-29 19:53:22] hanskrentel at yahoo dot de

Description:
------------
It's not possible to make use of variable aliasing in PHP when the alias is 
used 
within the use clause of a lambda function construct that is assigned to that 
variable (recursion).

PHP denies to do what it is commanded with a Fatal error: Cannot destroy active 
lambda function. But the function is not destroyed. It's just not that the 
variable container contains the identifier of it.

I'd like to change that, and I don't want to waste another variable name. Also 
I 
don't understand how I can actually destroy something I should not have any 
access 
to from PHP userland.

Or if that is intended, please allow us to destroy the active lambda making the 
function return NULL and continue to execute.



Test script:
---------------
$f = function() use (&$f) {
    $f = function() {echo "hello"};
};
$f();
$f();


Expected result:
----------------
hello

Actual result:
--------------
Fatal error: Cannot destroy active lambda function 


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62452&edit=1

Reply via email to