How to delete a function at runtime in PHP?

王林
Release: 2023-09-06 13:16:02
forward
1489 people have browsed it

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);
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!