Home >Backend Development >PHP Tutorial >How to delete a function at runtime in PHP?

How to delete a function at runtime in PHP?

王林
王林forward
2023-09-06 13:13:061543browse

How to delete a function at runtime in PHP?

Functions and classes in PHP have global scope. This means that even if they are defined within the scope, they can be called outside the function and vice versa.

But PHP does not support function overloading, and it is not possible to redefine a previously declared function.

The function can be defined as an anonymous function and can be unset after it has finished running.

Below is the code example for the same -

if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc())
   $my_fn = create_function('&$v, $k', '$v = stripslashes($v);');
   array_walk_recursive(array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST), $my_fn);
   unset($my_fn);
}

Anonymous functions cannot be called within them. The solution is to use array_walk_recursive.

The above is the detailed content of How to delete a function at runtime in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete