Is there a good way to differentiate between variables or array indices set to NULL versus variable or array indices that haven't actually been set?
The only way I can see is to test if the variable or array index exists:
if ( array_key_exists( 'indexBeingTested', $array ) )
{
echo is_null( $array['indexBeingTested'] ) ? "is set and is NULL" : "is set and is NOT NULL";
}
else
{
echo "Never been set";
}
// or for variables:
$allVars = get_defined_vars(); // or use $GLOBALS
if ( array_key_exists( 'variableName', $allVars ) )
{
echo is_null( $variableName ) ? "is set and is NULL" : "is set and is NOT NULL";
}
else
{
echo "Never been set";
}
Did I miss something, or is this the only way to distinguish between not set and NULL?