YamdaBlam!

Tag: #webdev

Cannot use object of type stdClass as array

by 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.

1 Comment :, , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

Archives

All entries, chronologically...