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

后端 未结 5 888
小鲜肉
小鲜肉 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:51

    From this question:

    You can use rename_function

    
    

    and then redeclare the original function.
    override_function may work too.

    They are part of the Zend PHP Debugger, if that doesn't work then you can always try something like:

    function function1(){
     echo "1";
    }
    
    function function2(){
     echo "2";
    }
    
    $i = "function2";
    $i(); //  displays 2;
    

提交回复
热议问题