1

My Call gets back: print_r($response)

GetItemResponseType Object
(
    [Item:protected] => ItemType Object
        (
            [ApplicationData:protected] => 651034.9.3011
            [BuyerProtection:protected] => ItemEligible
            [BuyItNowPrice:protected] => AmountType Object
                (
                    [attributeValues] => Array
                        (
                            [currencyID] => EUR
                        )

                    [value:protected] => 0.0
                )

            [Country:protected] => DE

        )

)

I read this (How to get protected property of object in PHP), but I can't reproduce the solution.

How can I get the value of Country with i.e. this:

   function accessProtected($obj, $prop) {
      $reflection = new ReflectionClass($obj);
      $property = $reflection->getProperty($prop);
      $property->setAccessible(true);
      return $property->getValue($obj);
    }

I get nothing, if I call:

echo accessProtected($response, 'Country');

Regards, Matthias

Community
  • 1
  • 1
  • 1
    It's protected for a reason - there is very likely a "getter" method to retrieve this information already, it's doubtful you need to do this. – Dan Smith Feb 17 '15 at 11:18
  • 1
    possible duplicate of [How to get protected property of object in PHP](http://stackoverflow.com/questions/20334355/how-to-get-protected-property-of-object-in-php) – B001ᛦ Feb 17 '15 at 11:18

2 Answers2

1

You should create getter and setter functions which are public or static in your class.

David
  • 34,836
  • 11
  • 47
  • 77
1

the answer to my question is:

echo $response->Item->Country;

Thank You.