Re: XML array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 5, 2011 at 6:43 PM, Tamara Temple <tamouse.lists@xxxxxxxxx>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/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux