Re: XML array
| From: | Stuart Dallas | Date: | Tue, 05 Jul 2011 17:48:04 +0000 |
| Subject: | Re: XML array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313918@lists.php.net to get a copy of this message | ||
On Tue, Jul 5, 2011 at 6:43 PM, Tamara Temple <tamouse.lists@gmail.com>wrote:
>
> On Jul 5, 2011, at 10:47 AM, Stuart Dallas wrote:
>
>
>> $arr[] = array('name' => (string)$book->name, 'author' =>
>> (string)$book->author);
>> }
>>
>
> Interesting -- is the casting to string type necessary there? I haven't
> done that before, and it seems to have worked ok...
Depends whether you want strings or not. $book->name is a SimpleXMLElement
object, so if you want the string value it needs to be cast to a string.
This will be implicitly done if you use the variable where PHP would expect
a string, but in the name of defensive programming I always cast XML values
to the type I expect/want them to be.
Remove the casts in that snippet and run it - you'll see the variables are
not strings.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/