How to check if JSON object is empty in PHP?

后端 未结 5 2117
别那么骄傲
别那么骄傲 2020-12-15 04:57

I\'m reading JSON data with PHP and that data contains empty objects (like {}). So the problem is, I have to handle the case when object is empty in different m

5条回答
  •  时光取名叫无心
    2020-12-15 05:30

    Try without using empty() which is:

    get_object_vars($obj) ? TRUE : FALSE;
    

    On PHP docs we can read the note:

    When using empty() on inaccessible object properties, the __isset() overloading method will be called, if declared.

    Which means when using empty() on an object which is having __get() method, it will always return True.

提交回复
热议问题