Re: XML array

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

 




On Jul 5, 2011, at 12:48 PM, Stuart Dallas wrote:

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.

Ah, thanks for that information. I guess I have just been lucky so far. I will update my code and my style there to make it more accurate and defensible.



[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