ID:               6333
 Comment by:       jon at fuck dot org
 Reported By:      ewdafa at ewdafa dot b0rk dot co dot uk
 Status:           Closed
 Bug Type:         Performance problem
 Operating System: linux-2.2.16
 PHP Version:      4.0.1pl2
 New Comment:

create_function() is operating as it should, yes, but there is still no
way to delete a function during the execution of a script. for silly
things like irc bots it gets handy to be able to rehash your function
set on the fly, which is possible, but you lose track of the functions
you have created thus far when you redefine your array of hashes.



i suggest a delete_function($foo) that removes the created function
from memory and renders the hash in $foo useless.



another useful one would be redefine_function(&$foo,
create_function(...)) that shortcuts the delete/create step for us.



this comes in handy for silly things like irc bots, when you have a
large set of functions to be rehashed without losing your connection to
the server by terminating the script.


Previous Comments:
------------------------------------------------------------------------

[2003-12-26 18:27:54] josh at mykoala dot com

It's been said that this is just how the function works, 

but it seems as though destroying allocations for an 

anonymous function when redefining to the same variable 

would be the way to handle it.  Example:



for ($i=0; $i<10; $i++) {

        $echoit = create_function('$wha', 'echo $wha;');

        echo memory_get_usage();

        $echoit(" on iteration: #$i\n");

}



How else can you dynamically modify function or code 

without reloading a script?

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

[2000-09-07 11:43:23] [EMAIL PROTECTED]

This isn't a bug but how it works. Each create_function() call creates
a new unique function. So obviously if you define zillions in an
infinite loop you'll run out of memory.

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

[2000-08-24 09:57:38] ewdafa at ewdafa dot b0rk dot co dot uk

the following code causes PHP to continually eat more and more memory
where it should be destroying the old reference for $func.



while(1) {

        $array = array();

        $func = create_function('', "return 0;");

        $array[] = $func;

        $func = 0;

        echo "sleeping for a second.\n";

        sleep(1);

}



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


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

Reply via email to