Re: XML array
| From: | Tamara Temple | Date: | Tue, 05 Jul 2011 18:03:54 +0000 |
| Subject: | Re: XML array | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313921@lists.php.net to get a copy of this message | ||
On Jul 5, 2011, at 12:48 PM, Stuart Dallas wrote:
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.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.