Search code examples
phpebay-api

PHP: How can I get protected values of an object?


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


Solution

  • the answer to my question is:

    echo $response->Item->Country;
    

    Thank You.