fork download
  1. <?php
  2.  
  3. $disabled_funcs = [];
  4.  
  5. // original code
  6. function func ($msg) {
  7. echo "$msg\n";
  8. }
  9.  
  10. //The wrapped one:
  11.  
  12. function _func () {
  13. global $disabled_funcs;
  14. $func = substr (__FUNCTION__, 1);
  15. if (isset($disabled_funcs[$func]))
  16. throw new Exception ("Function $func is disabled.");
  17. }
  18.  
  19. function disable_func ($name) {
  20. global $disabled_funcs;
  21. $disabled_funcs[$name] = 1;
  22. }
  23.  
  24. function enable_func ($name) {
  25. global $disabled_funcs;
  26. if (isset($disabled_funcs[$name]))
  27. unset ($disabled_funcs[$name]);
  28. }
  29.  
  30. //Call the function:
  31. _func ("Func not disabled.");
  32. disable_func ("func");
  33. try {
  34. _func ("Exception will be raised, this will not be displayed");
  35. } catch (Exception $e) {
  36. echo $e->getMessage() . PHP_EOL;
  37. }
  38. enable_func ("func");
  39. _func ("Func enabled");
  40.  
  41.  
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Func not disabled.
Function func is disabled.
Func enabled