i have sometimes following error Fatal error: Cannot use object of type stdClass as array in.. with this function:
function deliciousCount($domain_name)
{
$data = json_decode(
file_get_contents(
"http://feeds.delicious.com/v2/json/urlinfo/data?url=$domain_name"
)
);
if ($data) {
return $data[0]->total_posts;
} else {
return 0;
}
}
$delic = deliciousCount($domain_name);
but this error happen sometimes only for specific domains any help?
[ ... ].json_decodewill return false or null if there is nothing to decode; therefore, his function would return false thus evading the error.[{"url":...}]) and other times an empty object ({}). For no-existing domains like example.example[]or{}.