0

I am trying to get the "Id" value from an object an API returns.

This is what I get back from an the array $IS_user[0] which the API returns:

object(Contact)#165 (5) {
  ["customFieldFormId"]=>
  int(-1)
  ["fields":protected]=>
  NULL
  ["table":protected]=>
  string(7) "Contact"
  ["data":protected]=>
  array(78) {
    ["Id"]=>
    '1' 
.................

I want the Id so tried $IS_user[0]->data['Id']

But it broke.

Packy
  • 3,405
  • 9
  • 50
  • 87
  • 3
    its a protected property, check the API if its has a specific method to get the ID – Kevin Aug 04 '16 at 23:12
  • 1
    Have you tried casting it as an array: $array = (array) $IS_user[0]->data; http://stackoverflow.com/questions/20334355/how-to-get-protected-property-of-object-in-php. Note: this is a hack. – Nitin Aug 04 '16 at 23:43
  • 1
    @Nitin If you cast it to an array, shouldn't it be `[chr(0).'*'.chr(0).'data']` instead of `->data`? – Barmar Aug 05 '16 at 00:20
  • @Barmar you are right. My mistake. – Nitin Aug 05 '16 at 08:34

0 Answers0