How to unset a function definition just like we unset a variable?

后端 未结 5 889
小鲜肉
小鲜肉 2020-12-10 11:15

I want to define a function and unset it after its use just like we do with variables.

$a = \'something\';
unset($a);
echo $a; // outputs nothing
         


        
5条回答
  •  春和景丽
    2020-12-10 11:48

    A solution that avoids the requirement to unset a function and still use traditional functions....

    1. Place your function into a separate file
    2. Use require_once to call the file with the functions

    This way, if you are looping through code, you wont get an issue with calling the same function twice. I find this a neater solution and it makes it easier to call. you can then use url extensions to call groups of function or classes.

    Clearly this doesn't answer the request to remove, unset or destroy a function but it provides an alternate approach which may prove useful.

提交回复
热议问题