Re: SimpleXML returning attributes as objects instead of strings
| From: | Sterling Hughes | Date: | Mon, 02 Aug 2004 20:58:59 +0000 |
| Subject: | Re: SimpleXML returning attributes as objects instead of strings | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-11833@lists.php.net to get a copy of this message | ||
iterators...
On Mon, 02 Aug 2004 16:53:49 -0400, David Sklar <sklar@sklar.com> wrote:
> SimpleXML returns attribute values as SimpleXMLElement objects instead
> of strings. E.g, given this:
>
> $sxe = simplexml_load_string('<octopus arms="eight" legs="">Doc
> Ock</octopus>');
>
> $sxe['arms'] and $sxe['legs'] are SimpleXMLElement objects.
>
> This mostly works OK, but causes problems when using empty() to test if
> an attribute has a value. empty($sxe['arms']) is false, but so is
> empty($sxe['legs']).
>
> An easy workaround is to use strlen() instead of empty(), I suppose
> (except if an attribute value is "0"), but I am wondering why SimpleXML
> works this way.
>
> Thanks,
> David
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>