skip to Main Content

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


  1. Since DTSeBaySDKTypesRepeatableType implements ArrayAccess interface, you can access the items of the private $data array as follows:

    foreach ($ItemSpecific as $item) {
      var_dump($item);
    }
    

    or by index: $ItemSpecific[0]. But it’s more likely that you need to iterate the object in one way or another.

    Login or Signup to reply.
  2. 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.

    <?php
    function parse($obj, $start="[", $end = "]"){
        $string = json_encode($obj);
        $s = strpos($string, $start) + 1;
        $e = strpos($string, $end);
        $diff = $e - $s;
        return substr($string, $s, $diff);
    }
    
      echo parse($ItemSpecific->Value);
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search