0

My object received to variable $data from an API looks like this:

        Data Object
        (
            [serviceContext:DataService:private] => ServiceContext Object
                (
                    [info1] => abcde
                    [serviceType] => 123
                 )
        )

I want to retrive info1

I tried echo $data->serviceContext:DataService:private; but that seems to be a syntax error caused by the :

I tried echo $data->serviceContext->info1; which results in:

PHP Fatal error:  Cannot access private property Data::$serviceContext 

What's the correct way to retrieve the elements? Thank you

user2029890
  • 2,493
  • 6
  • 34
  • 65
  • `var_dump($data->serviceContext);` what do you see? – Martin Dec 12 '17 at 16:49
  • Consider looking at the methods for the object; you do have a class definition don't you? Perhaps in the API documentation – Mark Baker Dec 12 '17 at 16:49
  • 1
    `Cannot access private property` This is a private property. You want to be using a *get* method to view this property. – Martin Dec 12 '17 at 16:50
  • 2
    You're attempting to access a `private` data member of an object from outside of the object. This isn't possible. Look into `public` vs. `private` in objects. Instead, you will want to find the appropriate `public` object method to get this value. – B. Fleming Dec 12 '17 at 16:50
  • https://stackoverflow.com/a/20334749/4248328 And https://stackoverflow.com/a/10536163/4248328 – Alive to die - Anant Dec 12 '17 at 16:53
  • Do you see where it says `private`? The error message is saying you cannot access `$serviceContext`, why? because its private. – Daniel Feb 09 '18 at 21:15

0 Answers0