Bug #47015 [Asn->Opn]: Trouble with CDATA for single (not multiple) elements

From: Date: Tue, 24 Oct 2017 06:15:35 +0000
Subject: Bug #47015 [Asn->Opn]: Trouble with CDATA for single (not multiple) elements
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211993@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47015&edit=1 ID: 47015 Updated by: kalle@php.net Reported by: walshes at gmail dot com Summary: Trouble with CDATA for single (not multiple) elements -Status: Assigned +Status: Open Type: Bug Package: SimpleXML related Operating System: Linux PHP Version: 5.2.8 -Assigned To: rrichards +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2009-01-06 17:13:01] phpwnd at gmail dot com The reproduce code is unnecessarily complicated and, I believe, incorrect. Nodesets/nodes should not be cast as arrays, and if you don't, it works as expected. Reproduce code: --------------- $raw_xml = '<TopLevel><Cues><CueID><![CDATA[123]]></CueID></Cues></TopLevel>'; $TopLevel = simplexml_load_string($raw_xml); foreach ($TopLevel->Cues->CueID as $CueID) { echo $CueID, "\n"; } Expected result: ---------------- 123 Actual result: -------------- 123 ------------------------------------------------------------------------ [2009-01-06 09:27:01] walshes at gmail dot com Description: ------------ The example below fails to run right. If there are 2 'CueID' elements, it works. If there are 1 or 2 non-CDATA CueID elements, it also works. Reproduce code: --------------- $raw_xml = '<TopLevel><Cues><CueID><![CDATA[123]]></CueID></Cues></TopLevel>'; $xml = @new SimpleXMLElement($raw_xml); $cues = (array)$xml->Cues; $cues = (array)$cues['CueID']; if ($cues) { foreach ($cues as $c) { echo "got $c<BR>"; } } else { echo "SHE BROKE!"; } Expected result: ---------------- Should print 123 Actual result: -------------- SHE BROKE is printed ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47015&edit=1

« previous php.bugs (#211993) next »