php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47015 Trouble with CDATA for single (not multiple) elements
Submitted: 2009-01-06 09:27 UTC Modified: 2017-10-24 06:15 UTC
Votes:2
Avg. Score:1.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: walshes at gmail dot com Assigned:
Status: Open Package: SimpleXML related
PHP Version: 5.2.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: walshes at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-06 09:27 UTC] 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 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-06 17:13 UTC] 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
 [2017-10-24 06:15 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: rrichards +Assigned To:
 [2024-05-03 09:26 UTC] brandy587northrop at outlook dot com
Thanks for posting something like this. It's so interesting and informative. (https://github.com)(https://www.mydestiny-card.com)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 19:01:29 2024 UTC