I know this question seems hacky and weird, but is there a way to remove a function at runtime in PHP?
I have a recursive function declared in a \"if\" block and wan
I too see very little reason to let a function "live" or "not live" depending on a condition, but to answer the question, it's sort of possible using anonymous functions. @Gordon already outlined how it's done. Starting with PHP 5.3.0, you can also use anonymous functions as follows. (There is no functional difference to the create_function() approach.)
if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc())
{
$stripslashes_deep = function($value)
{
return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
}
$_POST = array_map($stripslashes_deep, $_POST);
$_GET = array_map($stripslashes_deep, $_GET);
$_COOKIE = array_map($stripslashes_deep, $_COOKIE);
$_REQUEST = array_map($stripslashes_deep, $_REQUEST);
unset ($stripslashes_deep);
}