I’m using eBay API which returns:
DTSeBaySDKTypesRepeatableType Object
(
[data:DTSeBaySDKTypesRepeatableType:private] => Array
(
[0] => 60
)
[position:DTSeBaySDKTypesRepeatableType:private] => 0
[class:DTSeBaySDKTypesRepeatableType:private] => DTSeBaySDKShoppingTypesNameValueListType
[property:DTSeBaySDKTypesRepeatableType:private] => Value
[expectedType:DTSeBaySDKTypesRepeatableType:private] => string
)
… and if I try to access it like so:
echo $ItemSpecific->Value->{0};
… I get this error:
Notice: Undefined property: DTSeBaySDKTypesRepeatableType::$0 in …
2
Answers
Since
DTSeBaySDKTypesRepeatableType
implementsArrayAccess
interface, you can access the items of the private$data
array as follows:or by index:
$ItemSpecific[0]
. But it’s more likely that you need to iterate the object in one way or another.I use to run into this same issue. The problem is that the information you want to parse out appears to be a private property of an object. Private properties of an object are restricted to the object. Standard practice of getting a private property to call a public function with in the object to output the value. It’s likely that such a function does not exist and therefore you cannot parse the information.
These rules, however, will only apply with in the realm of PHP. If you change this information into a static value, these rules will no longer apply.
Now I do not have a sample of your exact API result so you might have to change the parameters a bit, but this general idea should solve your problem.