YamdaBlam!

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.

:, , , , , ,
1 comment for this entry:
  1. Tweets that mention Cannot use object of type stdClass as array - YamdaBlam! -- Topsy.com

    [...] 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.

Leave a Reply

Powered by WP Hashcash

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