Check for is_object

Without this , it give php-warning-invalid-argument-supplied-for-foreach error.