Tag: #webdev
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.