|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-03-04 11:22 UTC] alepane at gmail dot com
Description:
------------
The instruction unset($seg_ref->{0}) works in PHP5.6 but not in PHP7 ... I haven't found this behaviour's change in any doc, so it's probably a bug.
The attached example in PHP 5.6 returns the dom without <seg id="A1"/>, in PHP 7 returns also that element (so the unset is not working).
Using $seg_ref[0] works in both version.
Test script:
---------------
<?php
$data='<data>
<seg id="A1"/>
<seg id="A2"/>
<seg id="A3"/>
<seg id="A4"/>
<seg id="A5"/>
</data>';
$doc=new SimpleXMLElement($data);
$seg_ref = $doc->seg;
unset($seg_ref->{0});
echo $doc->asXml();
Expected result:
----------------
<data>
<seg id="A2"/>
<seg id="A3"/>
<seg id="A4"/>
<seg id="A5"/>
</data>
Actual result:
--------------
<data>
<seg id="A1"/>
<seg id="A2"/>
<seg id="A3"/>
<seg id="A4"/>
<seg id="A5"/>
</data>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
->{0} wasn't supported to begin with; like I said it should have corresponded to a <0> element, but that's not valid XML. The fact that it did work was a side-effect of SimpleXMLElement's buggy implementation of the -> and [] operators, and in the 15 months since 7.0 it seems nobody else was making use of it. Do you feel strongly that it should be documented?