Doc #75137 [NEW]: Undocumented break from 5.6 using XML namespaces and assigning value by key.
| From: | marijn at suninet dot org | Date: | Wed, 30 Aug 2017 13:46:59 +0000 |
| Subject: | Doc #75137 [NEW]: Undocumented break from 5.6 using XML namespaces and assigning value by key. | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-14939@lists.php.net to get a copy of this message | ||
From: marijn at suninet dot org
Operating system: Linux
PHP version: 7.0.22
Package: SimpleXML related
Bug Type: Documentation Problem
Bug description:Undocumented break from 5.6 using XML namespaces and assigning value by key.
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 bug report at https://bugs.php.net/bug.php?id=75137&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75137&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75137&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75137&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75137&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75137&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75137&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75137&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75137&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75137&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75137&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75137&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75137&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75137&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75137&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75137&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75137&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75137&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75137&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75137&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75137&r=mysqlcfg