Reference PHP documentation: empty - Check whether a variable is empty
Obviously obj is not empty~
Test it:
print_r($obj);
Game Object ( )
empty Or non-empty is defined, don’t guess...
objects have been instantiated, then empty
will definitely not be empty. I understand empty
empty(''); //true empty(0); //true empty('0'); //true empty(NULL); //true empty([]); //true empty(array(array())); //false $a;//只定义不赋值 empty($a);//true class AA {} $aa = new AA(); empty($aa);// false, 对象真实存在, 不为空 class BB { public $name; } $bb = new BB(); empty($bb->name); //true
This is obvious It’s not empty. Empty is generally used to judge variables. In fact, it has no practical effect when you judge an object.
New an empty object is different from assigning an empty variable or an empty array.
Or you can print it out. Take a look, object(Game)[1]
This is what is printed,
The above is php empty. Isn’t it an object without attributes that will return true? For more related content, please pay attention to the PHP Chinese website (www.php.cn)!