stdClass Objects inside Objects in an Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eqdigital
Forum Newbie
Posts: 1
Joined: Tue Dec 22, 2009 2:18 pm

stdClass Objects inside Objects in an Array

Post by eqdigital »

I'm having some trouble dealing with stdClass object inside a stdClass object inside an array. I am trying to get the 'Source' value from this. I've tried this several different ways to no avail. It's entirely likely that I'm missing something embarrassingly simple...

$result =
Array ( [0] => stdClass Object ( [url] => stdClass Object ( [Source] => http://someurl.com/someimage.JPG ) ) )


$imgurl = $result->URL->Source;

I've also tried:
$object = $result[0];
$imgurl = $object->url->Source;

and in both cases

Server Error:
PHP Notice: Trying to get property of non-object

Ok, so the server error tells me that the array is not an object, which made sense before we broke out the $object, but still receiving this same error. I've also tried combining this with an array_values function, but get the same error. I've also tried get_object_vars and array_keys functions...


So how do I get the value of an object, inside an object, that's inside an array?


Thanks in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: stdClass Objects inside Objects in an Array

Post by requinix »

$result[0]->url->Source should work.

What do you get if you do a var_export of $result?
Post Reply