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:
- // Get records from the future!
- $ims = (new \DateTimeImmutable())->add(new \DateInterval('P1D'))->format("Y-m-d\TH:i:s+00:00");
- try {
- $mdata = $m->getRecords(null, null, null, null, null, ['if-modified-since' => $ims ])->getData();
- } catch (\Exception $e) {
- if ($e->getMessage() == "No Content") {
- $mdata = [];
- } else {
- throw $e;
- }
- }
- 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.