Bug #68946 [Opn->Ver]: simplexml_load_string() result depends on formatting of xml string

From: Date: Tue, 26 May 2015 20:25:49 +0000
Subject: Bug #68946 [Opn->Ver]: simplexml_load_string() result depends on formatting of xml string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192901@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68946&edit=1 ID: 68946 Updated by: cmb@php.net Reported by: danielhintermann at yahoo dot de Summary: simplexml_load_string() result depends on formatting of xml string -Status: Open +Status: Verified Type: Bug Package: SimpleXML related Operating System: Windows PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: Confirmed: <http://3v4l.org/c8RMA>. (Already fixed in master.) Previous Comments: ------------------------------------------------------------------------ [2015-05-26 19:28:24] cmb@php.net Related To: Bug #61335 ------------------------------------------------------------------------ [2015-05-26 19:06:17] cmb@php.net Related To: Bug #66084 ------------------------------------------------------------------------ [2015-05-26 12:16:43] cmb@php.net Related To: Bug #62639 ------------------------------------------------------------------------ [2015-01-29 20:21:02] cmbecker69 at gmx dot de I have to correct myself. According to the PHP language specification[1], comparing an object and a boolean for equality causes the object to be converted to boolean. Apparently, this is not documented in the PHP manual. Anyhow, conversion to boolean is documented in the PHP manual[2], and all (PHP 5) objects are converted to true, except "SimpleXML objects created from empty tags". Unfortunately, this description is confusing, at best. [1] <https://github.com/php/php-langspec> [2] <http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting> ------------------------------------------------------------------------ [2015-01-29 19:37:26] cmbecker69 at gmx dot de The comparison with == false causes $oXml to be cast to a scalar by calling it's __toString() method. The behavior of SimpleXmlElement::__toString() is documented as[1]: | Returns text content that is directly in this element. Does not | return text content that is inside this element's children. So basically you have '' == false // => true vs. ' ' == false // => false This is not a bug, but rather intended and documented behavior. [1] <http://php.net/manual/en/simplexmlelement.tostring.php> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=68946 -- Edit this bug report at https://bugs.php.net/bug.php?id=68946&edit=1

« previous php.bugs (#192901) next »