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
Initial function definition looks like:
// includes/std_functions.php
if (! function_exists('the_function')) {
function the_function() {
global $thefunction;
return call_user_func_array($thefunction, func_get_args());
}
$GLOBALS['thefunction'] = function() {
echo 'foo';
};
}
if you have a test condition that allows you to rewrite code:
// somewhere in your code
if () {
$GLOBALS['thefunction'] = function() {
echo 'bar';
};
}
if you are overloading in another include that will be loaded before or after the original file:
// includes/custom_functions.php
if (! function_exists('the_function')) {
function the_function() {
global $thefunction;
return call_user_func_array($thefunction, func_get_args());
}
}
$GLOBALS['thefunction'] = function() {
echo 'bar';
};