Doc #75137 [Opn]: Undocumented break from 5.6 using XML namespaces and assigning value by key.
| From: | cmb@php.net | Date: | Thu, 31 Aug 2017 14:31:44 +0000 |
| Subject: | Doc #75137 [Opn]: Undocumented break from 5.6 using XML namespaces and assigning value by key. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14941@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75137&edit=1
ID: 75137
Updated by: cmb@php.net
Reported by: marijn at suninet dot org
Summary: Undocumented break from 5.6 using XML namespaces and
assigning value by key.
Status: Open
Type: Documentation Problem
Package: SimpleXML related
Operating System: Linux
PHP Version: 7.0.22
Block user comment: N
Private report: N
New Comment:
According to <https://3v4l.org/W5n3d> the behavioral
change has
been introduced in PHP 7.0.12.
Previous Comments:
------------------------------------------------------------------------
[2017-08-30 13:46:56] marijn at suninet dot org
Description:
------------
Hi,
I've been looking around but I haven't been able to find anything. If you assign a value
to an XML element by using an array key when XML namespaces are used the behaviour is changed
between PHP 5.6 and PHP 7.0. This is something we couldn't anywhere in the documentation around
backwards incompatibility. It could have something to do with "Changes to the handling of
indirect variables, properties, and methods" but from my understanding reading that section
that is about when you use dynamic variable assignments which is not the case here.
In the expected/actual result you can see the difference. The expected result is what you get when
running the sample code in PHP 5.6 and the actual result is what you get when running the sample
code in PHP 7.0.
My guess is that this is not a bug but rather an undocumented backward incompatible change between
the PHP versions.
Regards,
Marijn.
Test script:
---------------
<?php
$xml = new SimpleXMLElement('<xml xmlns="http://xml" xmlns:foo="http://foo" xmlns:bar="http://bar" />');
$foo = $xml->addChild('foo', null, 'http://foo');
$tag = $foo->addChild('bar', null, 'http://bar');
$foo->bar[0] = 'Hello World!';
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
echo $dom->saveXML();
Expected result:
----------------
$ php-5.6 test.php
<?xml version="1.0"?>
<xml xmlns="http://xml" xmlns:foo="http://foo" xmlns:bar="http://bar">
<foo:foo>
<bar:bar>Hello World!</bar:bar>
</foo:foo>
</xml>
Actual result:
--------------
$ php-7.0 test.php
<?xml version="1.0"?>
<xml xmlns="http://xml" xmlns:foo="http://foo" xmlns:bar="http://bar">
<foo:foo>
<bar:bar/>
<foo:bar>Hello World!</foo:bar>
</foo:foo>
</xml>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75137&edit=1