How does php determine that an object is empty?

//
empty($var);
if($var){echo ""}

but an object variable fails to use the above method, is there any good way?

to supplement the application scenarios, we can temporarily think of the following two common situations:
1,
2 when the result set returned by the query database is in the form of an object, and a json string is converted into an object
. Of course, both cases can be converted into an array, so it is easy to determine whether the array is empty, but the array is not as written as the object, especially the array converted by the json string. There are often cases where the dimension is relatively large. When you want to access an item in it, you have to write a bunch of parentheses. Where is the object access property written? is that right?

Php
Jul.29,2021

do you want to judge that the number of object attributes is 0?
you can use the get_object_vars function to get the properties of an object


There is no saying that the

object is empty, either an instance of a class or not.

if you want to determine whether a variable has an object set, you can use the isset function.


if (count ($var))


Why should the object be judged to be empty? Could you give me a scene, please?


NULLisset;
:
"" ()
0 (0)
0.0 (0)
"0" (0)
NULL
FALSE
array() ()
$var; ()
empty.

var_dump($var === null);

isset, is_null can all


if (is_null ($var)) {
    //pass
}

determine whether an object is empty or not.

The

object cannot be judged to be empty, only to determine whether an attribute in it is empty

.
Menu