Say,
$obj = $this->someFunc(); // this returns an object
if(empty($obj)){
// suppose $obj is null, it does works correctly
}
In http://php.net/manual/en/function.empty.php, empty()
is only used for variables and arrays.
But, is it the correct way?
php has the function is_null()
to determine whether an object is null or not: http://php.net/manual/en/function.is-null.php
null
will cause empty()
to return true. However, if you're checking to see if that value is actually null, is_null()
is better suited for the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With