Cannot use object of type stdClass as array
by Jay on Jul.19, 2010, under PHP, Technology
Problem
I was getting this particular error when decoding JSON data block from a web service.
It basically is trying to assert that the data block is a different type to the variable which it is being assigned to.
Meet solution
Explore the data dump by using something like
echo ‘<pre>’; print_r($dataDump); echo ‘</pre>’;
and you will see the different data types for example:
stdClass Object ( [acc] => Array ….
Drill down through the structure to the data you want and check the data type of it. To prevent this error, simply apply some Type casting during the variable assignment. Bada-bing… problem, meet solution.
July 20th, 2010 on 14:27
[...] This post was mentioned on Twitter by John Paul Hayes, John Paul Hayes. John Paul Hayes said: New post on yamdablam http://j.mp/a4z6GU #webdev #php [...]
[WORDPRESS HASHCASH] The comment’s server IP (208.74.66.43) doesn’t match the comment’s URL host IP (74.112.128.10) and so is spam.