3 ms·
> There is no reason to use empty() over the not (!) operator unless there is the potential your property doesn't exist. I think empty() is one of the "magic"
by hrktb 12y ago
> There is no reason to use empty() over the not (!) operator unless there is the potential your property doesn't exist.
I think empty() is one of the "magic" parts of php that requires to know what it does really really well before trying to use it, especially before 5.5. For anyone learning the language, avoiding empty() altogether might be best/
One of the most interesting thing IMO is the suppression of any error occuring during the test. I.e "empty($object->is->null->but->we->call->nine->levels->of->properties)" won't generate any warning nor exception about calling properies on a null object, it just returns "true". It's powerful, while being a potential trap for anyone not aware of this behavior.