[UPHPU] Accessing object elements with punctuation marks

Richard K Miller richardkmiller at gmail.com
Thu Mar 29 12:07:02 MDT 2007


On Mar 29, 2007, at 11:36 AM, Alvaro Carrasco wrote:

>> But I can't access the next node down because it contains a hyphen:
>>
>>     print_r($xml->GetDomains->domain-list);  // produces error  
>> because of hyphen
>>
>>
> Wrap it in curly braces:
>
> $xml->GetDomains->{'domain-list'}
>

Awesome, that solved that.

Any idea about this?

This
<?php print_r($xml->GetDomains->{'domain-list'}); ?>
returns this:

SimpleXMLElement Object
(
     [domain] => Array
         (
             [0] => SimpleXMLElement Object
                 (
                     [sld] => abc.com
                 )

             [1] => SimpleXMLElement Object
                 (
                     [sld] => def.com
                 )
	)
)


But when I type
<?php print_r($xml->GetDomains->{'domain-list'})->domain; ?>
it returns this:

SimpleXMLElement Object
(
     [sld] => abc.com
)


I would expect the latter example to return both Objects in the array  
but it's only returning the 0th.  It's treating these two statements  
the same:

<?php print_r($xml->GetDomains->{'domain-list'})->domain; ?>
<?php print_r($xml->GetDomains->{'domain-list'})->domain[0]; ?>




More information about the UPHPU mailing list