Skip to content

Commit

Permalink
Fix Issue #223 - Implicit fetch cursor returns empty last value
Browse files Browse the repository at this point in the history
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);
  • Loading branch information
duliomatos committed Jul 14, 2016
1 parent 0365aa3 commit 86d4f9e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FacebookAds/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ private function isJsonObject($object) {
return false;
}

// Consider an empty array as not object
if (empty($object)) {
return false;
}

// A json object is represented by a map instead of a pure list
return array_keys($object) !== range(0, count($object) - 1);
}
Expand Down

0 comments on commit 86d4f9e

Please sign in to comment.