On Tue, Jul 5, 2011 at 6:43 PM, Tamara Temple <tamouse.li...@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 Dallas
3ft9 Ltd

Reply via email to