After installing PHP 5.5.9 on Ubuntu 14.04 (Trusty Tahr), I found this strange behavior with a switch
statement and the PHP_OS
constant.
I presume that in PHP 5.5.9 the switch statement is also checking for the same type (===)?
Or is it a PHP bug?
echo PHP_OS; // Linux
$os = PHP_OS;
switch (PHP_OS) {
case "WINNT":
echo 'Windows';
break;
case "Linux":
echo 'Linux';
break;
default:
echo 'Default';
break;
}
// Default
switch ((string) PHP_OS) {
case "WINNT":
echo 'Windows';
break;
case "Linux":
echo 'Linux';
break;
default:
echo 'Default';
break;
}
// Default
switch ($os) {
case "WINNT":
echo 'Windows';
break;
case "Linux":
echo 'Linux';
break;
default:
echo 'Default';
break;
}
// Linux