note 97049 deleted from simplexml.examples by danbrown
| From: | danbrown@php.net | Date: | Wed, 06 Oct 2010 14:50:05 +0000 |
| Subject: | note 97049 deleted from simplexml.examples by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173018@lists.php.net to get a copy of this message | ||
Note Submitter: posthy at NOSPAM dot com
----
Indeed. The intended behaviour is, that it will be a SimpleXMLElement. But this can cause some funny
sideeffects. Consider this:
<?php
$xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<root>
<value>0</value>
</root>";
$xmlobj = simplexml_load_string($xmlstr);
echo ((bool)$xmlobj->value ? "true" : "false");
?>
What do you think the result will be? I tell you: true!
Double casting may help, like (bool)(string)$xmlobj->value. It's ugly, but works.