Bug #66084 [Opn->Ver]: simplexml_load_string() mangles empty node name

From: Date: Fri, 04 Apr 2014 15:19:01 +0000
Subject: Bug #66084 [Opn->Ver]: simplexml_load_string() mangles empty node name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185088@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66084&edit=1

 ID:                 66084
 Updated by:         ab@php.net
 Reported by:        php at kenman dot net
 Summary:            simplexml_load_string() mangles empty node name
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   Win7
 PHP Version:        5.5Git-2013-11-12 (snap)
-Assigned To:        
+Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

@php at kenman dot net thanks for figuring the json thing out. What I meant previously - it actually
doesn't matter which function is used because often it will lead back to the get_properties
callback of the corresponding object. So this is not a var_dump issue at all :) If it's only to
see with var_dump, it's not of that prio as if that affects something like json.

Thanks


Previous Comments:
------------------------------------------------------------------------
[2014-04-03 17:30:35] php at kenman dot net

Related To: Bug #52463

------------------------------------------------------------------------
[2014-04-03 17:28:09] php at kenman dot net

I respectfully disagree, this is not merely a var_dump() issue. It may be true that there are
var_dump() anomalies here, but that's not the root of the issue.

The bug was exposed for me by missing data in the final output (JSON). I traced the data stream back
and discovered what's reported in this ticket.

Here's a reproduction that doesn't use var_dump():

echo
json_encode(simplexml_load_string('<a><b/><c><x/></c></a>')),
PHP_EOL;
echo json_encode(simplexml_load_string('<a><b/><c>
<x/></c></a>'));

------------------------------------------------------------------------
[2014-04-02 15:55:47] ab@php.net

Ref bug #52463, same var_dump() issue.

------------------------------------------------------------------------
[2013-11-14 21:57:55] php at kenman dot net

Just a note for anyone else that might come across this problem...

A little background: I create the XML originally as a DOMDocument, and then I call saveXML() to
generate the XML string. Then, I load that XML with simplexml_load_string() and eventually convert
it to JSON (don't ask about the convoluted process, not my choice).

I was able to work-around the issue by setting DOMDocument->formatOutput = true -- as per my last
note, the whitespace seems to hide the issue, and so now when I pass it to simplexml_load_string() I
get the expected output.

------------------------------------------------------------------------
[2013-11-14 17:23:21] php at kenman dot net

This just keeps getting stranger; apparently, whitespace influences this behavior.

Both of these lines produce the expected output:

    var_dump(simplexml_load_string('<a><b/><c>
<x/></c></a>')->c);
    var_dump(simplexml_load_string('<a><b/><c><x/>
</c></a>')->c);

However, whitespace added at any other point in the string will still produce the unexpected output.

------------------------------------------------------------------------


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=66084


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=66084&edit=1


Thread (23 messages)

« previous php.bugs (#185088) next »