Home > Backend Development > PHP Tutorial > Isn't php empty an object without attributes that will return true?

Isn't php empty an object without attributes that will return true?

PHP中文网
Release: 2016-08-29 08:50:55
Original
1657 people have browsed it

Reply content:


Reference PHP documentation: empty - Check whether a variable is empty

Obviously obj is not empty~

Test it:

print_r($obj);
Copy after login

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
Copy after login

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)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template