arrays - Parsing PHP object value
I have the following
Imgur\Api\Model\Basic Object ( [data:Imgur\Api\Model\Basic:private] => Array ( [id] => 1XgbfFV [title] => PIC 2 TITLE [description] => PIC 2 DESC [datetime] => 1472495069 [type] => image/jpeg [animated] => [width] => 590 [height] => 1382 [size] => 35307 [views] => 0 [bandwidth] => 0 [vote] => [favorite] => [nsfw] => [section] => [account_url] => [account_id] => 0 [in_gallery] => [deletehash] => tZUGIGuV9Bfv6lV [name] => PIC 2 NAME [link] => http://i.imgur.com/1XgbfFV.jpg [is_ad] => ) [success:Imgur\Api\Model\Basic:private] => 1 [status:Imgur\Api\Model\Basic:private] => 200 )
I trying get the [id] so I tried something like
$basic = $client->api('image')->upload($imageData); $data = $basic->id; print_r($data);
but value is empty. what should I do to get the value of [id] into $data
If this is the same code you're using in PHP to talk to the Imgur API then as you can see from the code it has a
60, which returns the private member. Because the member is private you can't access it directly from your
$basicobject, which appears to be an instance of
So instead you use the public getter like this...
All items in the data object are private. What you should do is in your Imgur class, create a new method
getDatawhich returns the data object.
You can also expand this further by creating a magic get method.
If doing it the magic method way, you can then just run,
$basic->idand it should respond with
1XgbfFVbecause of the magic getter.
If this is not a class that you have created, you will need to look at the API from Imgur package to determine if there is an accessor for the data array.