php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69169 Regression 5.2: simplexml_load_string parse wrongly when xml given in one row
Submitted: 2015-03-03 10:36 UTC Modified: 2015-05-27 17:49 UTC
From: nadavvin at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: SimpleXML related
PHP Version: 5.6.6 OS: windows,linux
Private report: No CVE-ID: None
 [2015-03-03 10:36 UTC] nadavvin at gmail dot com
Description:
------------
when remove, new lines and tab from the following XML,  it lost tag name in php > 5.2

instead of "item" appear "0".

test and failed in php 5.5.3 (linux), 5.6.6(windows)
work on: php 5.2 windows

There is also difference between 5.5.3 to 5.6.6 (parse wrong in different ways)

Test script:
---------------
<?php

$a = '<?xml version="1.0" encoding="UTF-8"?>
<root a="b">
	<row b="y">
		<item s="t" />
	</row>
	<row p="c">
		<item y="n" />
	</row>
</root>';

$simple_xml = @simplexml_load_string($a);
print_r($simple_xml);

$b = str_replace( array("\n", "\r", "\t"), "", $a );
var_dump($b);
$simple_xml = @simplexml_load_string($b);
print_r($simple_xml);




Expected result:
----------------
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [a] => b
        )

    [row] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [b] => y
                        )

                    [item] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [s] => t
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [p] => c
                        )

                    [item] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [y] => n
                                )

                        )

                )

        )

)

Actual result:
--------------
5.6.6:
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [a] => b
        )

    [row] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [b] => y
                        )

                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [s] => t
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [p] => c
                        )

                    [item] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [y] => n
                                )

                        )

                )

        )

)

5.5.3

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [a] => b
        )

    [row] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [b] => y
                        )

                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [s] => t
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [p] => c
                        )

                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [y] => n
                                )

                        )

                )

        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-03 19:46 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2015-03-03 19:46 UTC] requinix@php.net
http://3v4l.org/VAjaa

May just be the print_r() output since ->row[0]->item works fine.
http://3v4l.org/UcBUO
 [2015-03-04 08:24 UTC] nadavvin at gmail dot com
It's happen also in var_dump, json_encode:
var_dump($simple_xml);

echo json_encode($simple_xml);

http://3v4l.org/RUnot
 [2015-05-27 17:49 UTC] cmb@php.net
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-27 17:49 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: Fri Oct 11 03:01:27 2024 UTC