~ overflow ~

Fatal error: Cannot use object of type stdClass as array (php json_decode)

by z3n on Feb.17, 2010, under Coding, Notes, Tips & Hints

Problem:

$var=json_decode($_POST['something']);

echo $var['value'];

returns error: Fatal error: Cannot use object of type stdClass as array

Solution:

echo $var->value;

:, , , ,


2 comments for this entry:
  1. Marc

    Alternatively, you can pass “true” as a second parameter to json_encode, and it’ll be an associative array.

    $var=json_decode($_POST['something'],true);
    echo $var['value'];

  2. raja

    thanks mate , you are awesome ,

Leave a Reply

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!