Created
March 31, 2015 12:54
-
-
Save manuakasam/e317f10b6bbf5ecefd10 to your computer and use it in GitHub Desktop.
Is it really this bad to use goto in a switch statement? Imo this is much more user-friendly as far as readability AND code-maintenance is concerned.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$complexArray = [ | |
//... lots of stuff | |
'condition' => 'unknown' | |
]; | |
switch ($someThingElse) { | |
case 'foo': | |
default: | |
$complexArray['condition'] = 'foo'; | |
break; | |
case 'bar': | |
if ($otherCondition === false) { | |
$complexArray = addCondition($complexArray, 'bar'); | |
break; | |
} | |
$complexArray['condition'] = 'bar'; | |
break; | |
} | |
function addCondition($baseArray, $condition) { | |
$baseArray['condition'] = $condition; | |
return $baseArray; | |
} | |
$service->call($complexArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$complexArray = [ | |
//... lots of stuff | |
'condition' => 'unknown' | |
]; | |
switch ($someThingElse) { | |
case 'foo': | |
default: | |
foo: | |
$complexArray['condition'] = 'foo'; | |
break; | |
case 'bar': | |
if ($otherCondition === false) { | |
goto foo; | |
} | |
$complexArray['condition'] = 'bar'; | |
break; | |
} | |
$service->call($complexArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment