php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67116 Regression: Inconsistent parsing of Nodes w/o linefeed
Submitted: 2014-04-23 13:52 UTC Modified: 2015-05-27 17:48 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:5 (100.0%)
From: idefaye at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: SimpleXML related
PHP Version: 5.4.27 OS: Windows7 & IIS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: idefaye at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-23 13:52 UTC] idefaye at gmail dot com
Description:
------------
I was not able to find an existing claimed bug, hope I am not declaring it double.

Environment : 5.4.27nts under windows7 and IIS

If an xml node contains only one child-node with attributes, no values, we get a results inconsistent results depending if the XML file is formatted or not: linefeed are present or not.

The one with linefeed is consistent with the rest, but if it is compressed, then we get a different result.

For an example, here is a quick XML, note that linefeed do matter:
<?xml version="1.0" encoding="UTF-8"?>
<aa>
	<bs>
		<b>b</b>
	</bs>
	<cs><c>b</c></cs>
	<ds><d id="d"></d></ds>
	<es>
		<e id="e"></e>
	</es>
	<fs><f id="f"></f><f id="f"></f></fs>
</aa>

Here ds node will not give the same results as the other nodes, look at es node which is exactly the same with but with linefeeds.

You will note in the Actual result section that ds declares having an object with property name '0' when it should be named 'd'

This particularly fails when using things like get_object_vars(), it does not get the objects.

Test script:
---------------
$xml = simplexml_load_file("test.xml")
print_r($xml);

Expected result:
----------------
SimpleXMLElement Object
(
    [bs] => SimpleXMLElement Object
        (
            [b] => b
        )

    [cs] => SimpleXMLElement Object
        (
            [c] => b
        )

    [ds] => SimpleXMLElement Object
        (
            [d] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => d
                        )

                )

        )

    [es] => SimpleXMLElement Object
        (
            [e] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => e
                        )

                )

        )

    [fs] => SimpleXMLElement Object
        (
            [f] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [id] => f
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [id] => f
                                )

                        )

                )

        )

)


Actual result:
--------------
SimpleXMLElement Object
(
    [bs] => SimpleXMLElement Object
        (
            [b] => b
        )

    [cs] => SimpleXMLElement Object
        (
            [c] => b
        )

    [ds] => SimpleXMLElement Object
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => d
                        )

                )

        )

    [es] => SimpleXMLElement Object
        (
            [e] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => e
                        )

                )

        )

    [fs] => SimpleXMLElement Object
        (
            [f] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [id] => f
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [id] => f
                                )

                        )

                )

        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-23 13:53 UTC] idefaye at gmail dot com
Please note that in PHP5.3.9 it works properly, so it is a regression.
 [2015-03-11 17:24 UTC] idefaye at gmail dot com
I have tested again with version 5.4.38-nts and 5.3.29-nts and bug still exists. 
This makes reading XML files unreliable depending on how they are structured. Please correct, this bug has been declared for some time now.
 [2015-03-11 18:01 UTC] idefaye at gmail dot com
-Summary: Inconsistent parsing of Nodes w/o linefeed +Summary: Regression: Inconsistent parsing of Nodes w/o linefeed
 [2015-03-11 18:01 UTC] idefaye at gmail dot com
Changed title to regression to stress out the importance
 [2015-05-27 17:48 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-27 17:48 UTC] cmb@php.net
After further investigation it turned out that this is a duplicate
of bug #66084.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 19:01:27 2024 UTC