Skip to content

Instantly share code, notes, and snippets.

@iannsp
Created September 14, 2011 21:24
Show Gist options
  • Save iannsp/1217830 to your computer and use it in GitHub Desktop.
Save iannsp/1217830 to your computer and use it in GitHub Desktop.
get out switch workaround
<?php
$variavel = "valor";
// com switch
switch($variavel){
case "a": break;
case "b":break;
default :
}
// workaround 1
$functionStrategy = "func{$variavel}";
$retorno = (function_exists($functionStrategy))?$functionStrategy():defaultStrategy();
function a(){
// estrategia A
}
function b(){
//estrategia B
}
// workaround 2
function Strategy($functionStrategy, &$retvalue)
{
include_once "{$functionStrategy}.php";
$retvalue = (function_exists($functionStrategy))?$functionStrategy():defaultStrategy();
}
Strategy($variavel, $retorno);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment