How to check that an object is empty in PHP?

前端 未结 11 2072
不思量自难忘°
不思量自难忘° 2020-11-29 03:31

How to find if an object is empty or not in PHP.

Following is the code in which $obj is holding XML data. How can I check if it\'s empty or not?

11条回答
  •  一个人的身影
    2020-11-29 04:13

    there's no unique safe way to check if an object is empty

    php's count() first casts to array, but casting can produce an empty array, depends by how the object is implemented (extensions' objects are often affected by those issues)

    in your case you have to use $obj->count();

    http://it.php.net/manual/en/simplexmlelement.count.php

    (that is not php's count http://www.php.net/count )

提交回复
热议问题