note 98939 modified in function.create-function by danbrown
| From: | danbrown@php.net | Date: | Fri, 16 Jul 2010 17:07:08 +0000 |
| Subject: | note 98939 modified in function.create-function by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170916@lists.php.net to get a copy of this message | ||
To avoid memory problems, when creating a dynamic function within loops, register it as a global
variable, and check if it has already been set;
<?php
global $my_func;
if (!isset($my_func))
{
$my_func = create_function($args, $code);
}
$my_func();
?>
That way you don't end up creating the same function twice (or a couple of million of times, as
it happened to me...)
--was--
To avoid memory problems, when creating a dynamic function within loops, register it as a global
variable, and check if it has already been set;
global $my_func;
if (!isset($my_func))
{
$my_func = create_function($args, $code);
}
$my_func();
That way you don't end up creating the same function twice (or a couple of million of times, as
it happened to me...)
http://php.net/manual/en/function.create-function.php