Is there a case where I will get a different result if I use if ($somevar)
instead of if (!empty($somevar))
?
Aren't these two doing the exact same thing?
Not at all,
if ($somevar)
– This generates a notice if $somevar
is not set
if (!empty($somevar))
– This is functionally equivalent to if($somevar)
, but doesn't generate a notice.
empty()
does NOT produce E_NOTICE on undeclared variables
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.