Bug #68946 [Com]: simplexml_load_string() result depends on formatting of xml string

From: Date: Thu, 29 Jan 2015 19:37:27 +0000
Subject: Bug #68946 [Com]: simplexml_load_string() result depends on formatting of xml string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190319@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 Comment by: cmbecker69 at gmx dot de Reported by: danielhintermann at yahoo dot de Summary: simplexml_load_string() result depends on formatting of xml string Status: Open Type: Bug Package: SimpleXML related Operating System: Windows PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2015-01-29 15:35:24] danielhintermann at yahoo dot de Could be a duplicate of #68507. ------------------------------------------------------------------------ [2015-01-29 15:29:03] danielhintermann at yahoo dot de Description: ------------ First, the bug could also be triggered on PHP version 5.3.28 on windows. Secondly, it could be related to the issue Bug #61335. Depending on formatting of a xml string the comparing with '== false' gives different result. It is clear that the === operator should be used, however, the == operator still should give consistent results! Test script: --------------- <?php class TestComparisonOperator extends PHPUnit_Framework_TestCase { public function testWithoutSpaceFormat() { $oXml = simplexml_load_string($this->getXmlNoFormatting()); var_dump($oXml); $this->assertFalse($oXml == false); } public function testWithSpaceFormat() { $oXml = simplexml_load_string($this->getXmlWithSpaceFormat()); var_dump($oXml); $this->assertFalse($oXml == false); } private function getXmlNoFormatting() { return "<?BrightCloud version=bcap/1.1?><bcap><seqnum>1</seqnum></bcap>"; } private function getXmlWithSpaceFormat() { // look at the space after bcap tag! return "<?BrightCloud version=bcap/1.1?><bcap> <seqnum>1</seqnum></bcap>"; } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68946&edit=1

« previous php.bugs (#190319) next »