简体   繁体   中英

Differences in checking if a variable is not empty with !empty

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM