|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-06-29 19:53 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 12:00:01 2025 UTC |
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();This bug is really annoying. Here's another scenario that I just hit while refactoring: set_exception_handler(function($exception) { restore_exception_handler(); // boom echo "Exception handled, move along.\n"; }); throw new Exception; // fatal error: cannot destroy active lambda@john dot papaioannou: If it helps, you can prevent the error in your case by assigning the closure to a variable first, so that the exception handler can be reset without destroying the closure (here: $handler): set_exception_handler($handler = function($exception) { restore_exception_handler(); // boom echo "Exception handled, move along.\n"; }); throw new Exception; // fatal error gone now Demo: http://3v4l.org/bJv3p I know that this does not fix the underlying problem, just commenting in the hope this might be helpful for you.