note 97049 added to simplexml.examples
| From: | posthy at NOSPAM dot com | Date: | Tue, 30 Mar 2010 00:54:56 +0000 |
| Subject: | note 97049 added to simplexml.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167516@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 178.164.154.202
----
Manual Page -- http://www.php.net/manual/en/simplexml.examples.php
Edit -- https://master.php.net/note/edit/97049
Del: integrated -- https://master.php.net/note/delete/97049/integrated
Del: useless -- https://master.php.net/note/delete/97049/useless
Del: bad code -- https://master.php.net/note/delete/97049/bad+code
Del: spam -- https://master.php.net/note/delete/97049/spam
Del: non-english -- https://master.php.net/note/delete/97049/non-english
Del: in docs -- https://master.php.net/note/delete/97049/in+docs
Del: other reasons-- https://master.php.net/note/delete/97049
Reject -- https://master.php.net/note/reject/97049
Search -- https://master.php.net/manage/user-notes.php