12

Possible Duplicate:
Fatal error: Cannot use object of type stdClass as array in

Please I keep getting this error: Fatal error: Cannot use object of type stdClass as array in C:\XAMMP\xampp\htdocs\Yemi\geograph\table.php on line 31

This is the php I am trying to run:

php code

4
  • 11
    Please paste the actual code here, and not some screenshot of your code. Thanks Commented Mar 3, 2012 at 13:11
  • Yes, please post the actual code. We rely heavily on copy/pasting code examples to provide answers with bugfixes and annotation. Commented Mar 3, 2012 at 13:24
  • The response from 'Click' solved the problem. Question answered. Forum please note... Commented Mar 3, 2012 at 13:50
  • @akinboj when an answer solves your problem you are supposed to tick the green check mark next to it. And please: next time use the search function before asking a question that has been asked and answered numerous times before. There is a reason we force stackoverflow.com/questions/ask-advice on you and asked you to do your homework prior to asking. And you are also not supposed to ignore the suggestions we show when you type in your question. Commented Mar 3, 2012 at 13:50

1 Answer 1

44

You are actually trying to access the object as array.

I can guess you are having problem when you are using json_decode which is returning an object and inside the foreach loop you are trying to access it like an associative array.

Passing the second argument as true to json_decode force it to return associative array.

Make the below change.

Change your this code line

$items = json_decode($contents);

To

$items = json_decode($contents, true);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.