I just came across a strange situation. When I try the following code in $ php -a
, I receive an error:
php > var_dump(isset(null));
PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in php shell code on line 1
But when I do the same thing with empty(), everything is ok:
php > var_dump(empty(null));
bool(true)
Can anyone explain why I receive an error when I try isset(null)
?
Update
Thank you all for your answers. I asked this question just to make sense of why isset()
is behaving differently from empty()
.
To me, both of them are php functions and both accept a parameter. So, as any other function in php, calling isset(null)
should be a valid statement. Aren't we passing null as a value to isset() function? So why php consider it as an expression?