Skip to content

Commit 86d4f9e

Browse files
committed
Fix Issue #223 - Implicit fetch cursor returns empty last value
Summary: #223 When using Implicit Fetch the last object returned by Cursor is an empty, inexistant object. This was caused by a very subtle interaction with isJsonObject method. Test Plan: Sample code to detect error: use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\AdAccount; use FacebookAds\Cursor; Api::instance()->setLogger(new CurlLogger()); Cursor::setDefaultUseImplicitFetch(true); $result = array(); $params = array(); $fields = array( \FacebookAds\Object\Fields\AdFields::ID, \FacebookAds\Object\Fields\AdFields::NAME, ); $account = new AdAccount($account_id); $ads = $account->getAds($fields, $params); //$ads->setUseImplicitFetch(true); foreach ($ads as $ad) { $row = []; foreach ($fields as $field) { $row[$field] = $ad->$field; } $result[] = $row; } var_dump($result);
1 parent 0365aa3 commit 86d4f9e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/FacebookAds/Cursor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ private function isJsonObject($object) {
163163
return false;
164164
}
165165

166+
// Consider an empty array as not object
167+
if (empty($object)) {
168+
return false;
169+
}
170+
166171
// A json object is represented by a map instead of a pure list
167172
return array_keys($object) !== range(0, count($object) - 1);
168173
}

0 commit comments

Comments
 (0)