Created
February 5, 2014 18:26
-
-
Save loganlinn/8830023 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$a = array(); | |
$vals = [ | |
['"" ', ""], | |
['0 (int) ', 0], | |
['0.0 (float) ', 0.0], | |
['"0" (string) ', "0"], | |
['FALSE ', false], | |
['NULL ', null], | |
['array() ', []], | |
]; | |
echo "\nisset()\n"; | |
foreach ($vals as list($desc, $value)) { | |
echo "\t", $desc, " ", isset($value) ? "TRUE" : "FALSE", "\n"; | |
} | |
echo "\t", '$var (declared, no value) ', " ", isset($var) ? "TRUE" : "FALSE", "\n"; | |
echo "\t", '$a["x"] (undefined offset)', " ", isset($a['x']) ? "TRUE" : "FALSE", "\n"; | |
echo "\nempty()\n"; | |
foreach ($vals as list($desc, $value)) { | |
echo "\t", $desc, " ", empty($value) ? "TRUE" : "FALSE", "\n"; | |
} | |
echo "\t", '$var (declared, no value) ', " ", empty($var) ? "TRUE" : "FALSE", "\n"; | |
echo "\t", '$a["x"] (undefined offset)', " ", empty($a['x']) ? "TRUE" : "FALSE", "\n"; | |
echo "\nfalseyness\n"; | |
foreach ($vals as list($desc, $value)) { | |
echo "\t", $desc, " ", $value ? "TRUE" : "FALSE", "\n"; | |
} | |
echo "\t", '$var (declared, no value) ', " ", @($var ? "TRUE" : "FALSE"), " (PHP Notice)\n"; | |
echo "\t", '$a["x"] (undefined offset)', " ", @($a['x'] ? "TRUE" : "FALSE"), " (PHP Notice)\n"; | |
/* | |
* isset() | |
* "" TRUE | |
* 0 (int) TRUE | |
* 0.0 (float) TRUE | |
* "0" (string) TRUE | |
* FALSE TRUE | |
* NULL FALSE | |
* array() TRUE | |
* $var (declared, no value) FALSE | |
* $a["x"] (undefined offset) FALSE | |
* | |
* empty() | |
* "" TRUE | |
* 0 (int) TRUE | |
* 0.0 (float) TRUE | |
* "0" (string) TRUE | |
* FALSE TRUE | |
* NULL TRUE | |
* array() TRUE | |
* $var (declared, no value) TRUE | |
* $a["x"] (undefined offset) TRUE | |
* | |
* falseyness | |
* "" FALSE | |
* 0 (int) FALSE | |
* 0.0 (float) FALSE | |
* "0" (string) FALSE | |
* FALSE FALSE | |
* NULL FALSE | |
* array() FALSE | |
* $var (declared, no value) FALSE (PHP Notice) | |
* $a["x"] (undefined offset) FALSE (PHP Notice) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment