Why is this AWS call picking only the first element of the array (PHP/AWS)

Go To StackoverFlow.com

0

Using the AWS PHP SDK to play around with S3 for the first time

$res = $s3->list_objects($bucket);
var_dump($res);

Shows me that I have a Contents array with 4 elements in it

However var_dump($res->body->Contents) yields only one XMLObject instead of a php array with for elements like it should.

What's going on?

2012-04-04 00:45
by algorithmicCoder
Can you include in your question each of: vardump($res); vardump($res->body->Contents) - Nathaniel Ford 2012-04-04 00:47


1

The S3 library read the XML response and returns an XML/DOM object. It cannot be printed like a normal array. You are advised to iterate over it like it says in the PHP manual.

However, for quick tests you can cheat.

var_dump(json_decode(json_encode($xml)));

Personally, I would see if a JSON response can be returned - they are generally smaller, faster to parse, and easier to browse than DOMNode's or DOMLists.

2012-04-04 00:47
by Xeoncross
Ads