Skip to content

Instantly share code, notes, and snippets.

@berkes
Created September 20, 2012 08:03
Show Gist options
  • Save berkes/3754567 to your computer and use it in GitHub Desktop.
Save berkes/3754567 to your computer and use it in GitHub Desktop.
Isset acts weird in PHP.
<?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