Are these two statements executed identically, given $thing could be of any type?
if (!empty($thing)) {
// do stuff
}
if ($thing) {
// do stuff
}
I’m aware I could try it, but I’m not sure I’d catch all the edge cases… I’m afraid in some situations they would execute identically, but not all.
If
$thingis undefined, thenif ($thing)would throw a (non-fatal) error whileif (!empty($thing))would return false.See empty() in the PHP documentation.