2

Possible Duplicate:
php object attribute with dot in name

I'm dealing with PHP, getting an object returned by a Microsoft web service, and there is a period in the object name!

    object(stdClass)#22 (1) {
  ["DAE.Country"]=>
  array(24) {
    [0]=>
    object(stdClass)#23 (2) {
      ["CountryName"]=>
      string(4) "Asia"
      ["ID"]=>
      string(2) "27"
    }
}
}

How do I access an object in PHP with a period in its name?

$response->DAE_GetCountryListResult->DAE.Country;

and

$response->DAE_GetCountryListResult-['DAE.Country'];

both fail. Thank you for your time.

Community
  • 1
  • 1

1 Answers1

5

You can use this syntax to access the property you want:

$obj->{'DAE.Country'}

You can also use a variable and expressions inside the braces:

$prefix = 'DAE';
$name = 'Country';
$another_obj = $obj->{"$prefix.$name"};
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309