Vipul Sharma Vipul Sharma - 1 year ago 295
PHP Question

How to check if stdClass object is empty or not in php?

Possible Duplicate:

How to Check if an Object is empty in PHP

I have this empty object

Array (
[cart_items] => stdClass Object

When I use
, it doesn't work. When I use
, it returns one.

How can I check it?

Answer Source

Cast to an array first

$tmp = (array) $object;

The reason is, that an object is an object and there is no useful definition of "an empty object", because there are enough classes out there, that only contains methods, but no properties. Should they considered as "empty"?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download