Bug #76712 [PATCH]: Empty Tags are preserved if node value is overwritten with empty value

From: Date: Mon, 06 Aug 2018 22:08:39 +0000
Subject: Bug #76712 [PATCH]: Empty Tags are preserved if node value is overwritten with empty value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216645@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76712&edit=1 ID: 76712 Patch added by: cmb@php.net Reported by: frank dot mohaupt at brainworx dot audio Summary: Empty Tags are preserved if node value is overwritten with empty value Status: Open Type: Bug Package: SimpleXML related Operating System: Linux d45011cc91b7 4.9.93-boot2d PHP Version: 7.0.31 Block user comment: N Private report: N New Comment: The following patch has been added/updated: Patch Name: workaround Revision: 1533593319 URL: https://bugs.php.net/patch-display.php?bug=76712&patch=workaround&revision=1533593319 Previous Comments: ------------------------------------------------------------------------ [2018-08-06 14:22:14] frank dot mohaupt at brainworx dot audio Description: ------------ If the value of node "foo" is empty while adding the node, its output (SimpleXMLElement::asXML()) is "<foo/>". If the value of node "foo" is overwritten with an empty value ($sxe->foo = ''), its output is "<foo></foo>" instead of "<foo/>". Test script: --------------- $sxe = new SimpleXMLElement('<foo></foo>'); $sxe->addChild('bar'); $arrResults['empty node'] = $sxe->asXML(); $sxe = new SimpleXMLElement('<foo></foo>'); $sxe->addChild('bar', ''); $arrResults['empty string'] = $sxe->asXML(); $sxe = new SimpleXMLElement('<foo></foo>'); $sxe->addChild('bar'); $sxe->bar = ''; $arrResults['overwritten empty string'] = $sxe->asXML(); foreach($arrResults as $key => $strResult){ echo $key . ': ' . $strResult; } // output // empty node: <?xml version="1.0"?>\n<foo><bar/></foo>\n // empty string: <?xml version="1.0"?>\n<foo><bar/></foo>\n // overwritten empty string: <?xml version="1.0"?>\n<foo><bar></bar></foo>\n Expected result: ---------------- I expect to get the same result for all three cases. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76712&edit=1

« previous php.bugs (#216645) next »