isset() in php 5.3 seems to be behaving unexpectedly. I have a class called DB details that encapsulates a bunch of string properties with getters and setters.
$dbdetails->getDatabasename() evaluates to a string (“mydb”)
This throws a 500 error:
if(!isset($dbdetails->getDatabasename())){
//do something
}
This works fine
$databasename = $dbdetails->getDatabasename();
if(!isset($databasename)){
//do something
}
I wasn’t able to see any log output because apache sent back a 500 even though the error ini param is set (sic) to On. I know this is something to do with the isset call for sure.
Any idea what could be wrong, or did I find a PHP bug?
The
issetfunction checks whether a variable is set. Checking against$databasenameis valid, because it is a variable that can be set or not. Checking against a function is invalid, because it simply isn’t a variable.You probably want to use
is_null( $value )when checking the immediate result of a function.An example from the comments on the the is_null documentation: