Created
January 27, 2017 01:12
-
-
Save carlwiedemann/8a8636469abd8b556a40c55786d41423 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* # 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