Guest User

Untitled

a guest
Jan 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <?php
  2. $variavel = "valor";
  3.  
  4. // com switch
  5. switch($variavel){
  6.  
  7. case "a": break;
  8. case "b":break;
  9. default :
  10. }
  11.  
  12. // workaround 1
  13.  
  14. $functionStrategy = "func{$variavel}";
  15.  
  16. $retorno = (function_exists($functionStrategy))?$functionStrategy():defaultStrategy();
  17.  
  18.  
  19.  
  20. function a(){
  21. // estrategia A
  22. }
  23. function b(){
  24. //estrategia B
  25. }
  26.  
  27.  
  28. // workaround 2
  29.  
  30. function Strategy($functionStrategy, &$retvalue)
  31. {
  32. include_once "{$functionStrategy}.php";
  33.  
  34. $retvalue = (function_exists($functionStrategy))?$functionStrategy():defaultStrategy();
  35.  
  36. }
  37.  
  38.  
  39.  
  40. Strategy($variavel, $retorno);
Add Comment
Please, Sign In to add comment