Created
September 20, 2012 08:03
-
-
Save berkes/3754567 to your computer and use it in GitHub Desktop.
Isset acts weird in PHP.
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 | |
function foo($bar = NULL) { | |
if (isset($bar)) { | |
print "bar is set\n"; | |
var_dump($bar); | |
} | |
else { | |
print "bar is not set\n"; | |
var_dump($bar);//If not set should throw at least a NOTICE. | |
} | |
} | |
foo("hmm"); | |
#=> bar is set | |
#=> string(3) "hmm" | |
foo(); | |
#=> bar is not set | |
#=> NULL <- If it is NULL, it is set, not? *shakes head* | |
# On reading the documentation: isset() (http://uk.php.net/manual/en/function.isset.php) returns false for variables that _are_ set, but are set to NULL. At least it is documented... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment