Skip to content

Instantly share code, notes, and snippets.

@carlwiedemann
Created January 27, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlwiedemann/8a8636469abd8b556a40c55786d41423 to your computer and use it in GitHub Desktop.
Save carlwiedemann/8a8636469abd8b556a40c55786d41423 to your computer and use it in GitHub Desktop.
<?php
/**
* # EXPECTED
* $ php -f ./switch-is-broken.php
* the word alpha
* the word beta
* the default
* the default
* the number one
*
* # ACTUAL
* $ php -f ./switch-is-broken.php
* the word alpha
* the word beta
* the word alpha
* the default
* the number one
*/
main();
function main() {
test_switch('alpha');
test_switch('beta');
// This matches the first condition for some reason. :(
test_switch(0);
test_switch(NULL);
test_switch(1);
}
function test_switch($var) {
switch ($var) {
case 'alpha':
echo 'the word alpha' . PHP_EOL;
break;
case 'beta':
echo 'the word beta' . PHP_EOL;
break;
case 1:
echo 'the number one' . PHP_EOL;
break;
default:
echo 'the default' . PHP_EOL;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment