Php API Bug - PHP Warning when no data returned due to requesting Last Modified data

Php API Bug - PHP Warning when no data returned due to requesting Last Modified data

If no records are returned due to the If-Modified-Since header, the PHP API doesn't handle it correctly

In the example below, assume $m is a module:

  1. // Get records from the future!
  2. $ims = (new \DateTimeImmutable())->add(new \DateInterval('P1D'))->format("Y-m-d\TH:i:s+00:00");
  3. try {
  4. $mdata = $m->getRecords(null, null, null, null, null, ['if-modified-since' => $ims ])->getData();
  5. } catch (\Exception $e) {
  6. if ($e->getMessage() == "No Content") {
  7. $mdata = [];
  8. } else {
  9. throw $e;
  10. }
  11. }
  12. print count($mdata)." rows returned for module $mname\n";

As no data is being returned, the  $responseJSON["data"] is a bool, and you can' foreach over them, leading to this warning:

Warning: Invalid argument supplied for foreach() in /var/www/app/vendor/zohocrm/php-sdk/src/com/zoho/crm/library/api/handler/MassEntityAPIHandler.php on line 324

This can be fixed backend by actually returning an empty array, or by the frontend checking if something is an array before foreaching over it.