Take this code:
$json = file_get_contents($this->url, true);
$decode = json_decode($json, true);
foreach ($decode as $key => $value) {
...
}
Pretty simple, uh?
Passing a $json with up to 500 array elements…. works right!
Above that limit… the error is:
Warning: Invalid argument supplied for foreach() in
/c/website/retriever/WsGlassRetriever.php on line 19
Is there some memory limit for that function’s argument?
I didn’t found nothing about it in the docs. My version is PHP 5.2.17-rnx1.1 with Suhosin-Patch 0.9.7 (cli)
json_decodereturnsNULLif there is an error in the JSON syntax. I’ve just successfully tested on an array of 1000 elements and it ran just fine.Double-check that your JSON is correctly formatted. Even something as small as having single quotes instead of double, or forgetting to put a property name in quotes, or using a character outside the 32-127 range without correctly encoding it in UTF-8 can cause these problems.