[UPHPU] Accessing object elements with punctuation marks
Richard K Miller
richardkmiller at gmail.com
Thu Mar 29 13:28:46 MDT 2007
On Mar 29, 2007, at 12:17 PM, Alvaro Carrasco wrote:
>> 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]; ?>
>>
>>
> One of the quirks of simplexml, it assumes 'grab the first one'.
> It's actually intended behavior, as unintuitive as it is.
>
> I usually prefer xpath when grabbing data from xml, it's less quirky:
> $domains = $xml->xpath('/GetDomain/domain-list/domain');
>
Thanks for that explanation on Simplexml, and I like the XPath method
you suggested.
More information about the UPHPU
mailing list