php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71872 PHP registerNodeClass and reusing variable names
Submitted: 2016-03-21 16:29 UTC Modified: 2016-05-11 14:57 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: jacksonpauls at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.0.6 OS: Linux - Fedora 23
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jacksonpauls at gmail dot com
New email:
PHP Version: OS:

 

 [2016-03-21 16:29 UTC] jacksonpauls at gmail dot com
Description:
------------
When registering a new base node type with registerNodeClass: if I re-use variable names for created elements, then custom properties revert to their default value.

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

class myDOMElement extends DOMElement
{
    public $myProp = 'Some default';
}

$doc = new DOMDocument();
$doc->registerNodeClass('DOMElement', 'myDOMElement');

$node = $doc->createElement('a');
$node->myProp = 'A';
$doc->appendChild($node);

# This seems to alter node A in $doc, not what I expected:
$node = $doc->createElement('b');
$node->myProp = 'B';
$doc->appendChild($node);

# Note: $nodeC instead of $node, this works fine. 
$nodeC = $doc->createElement('c');
$nodeC->myProp = 'C';
$doc->appendChild($nodeC);

foreach ($doc->childNodes as $n) {
    echo 'Tag ', $n->tagName, ' myProp:', PHP_EOL;
    var_dump($n->myProp);
}

Expected result:
----------------
Tag a myProp:
string(1) "A"
Tag b myProp:
string(1) "B"
Tag c myProp:
string(1) "C"

Actual result:
--------------
Tag a myProp:
string(12) "Some default"
Tag b myProp:
string(1) "B"
Tag c myProp:
string(1) "C"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-11 14:57 UTC] jacksonpauls at gmail dot com
-PHP Version: 7.0.4 +PHP Version: 7.0.6
 [2016-05-11 14:57 UTC] jacksonpauls at gmail dot com
There's now a detailed explanation of why this happens here: http://stackoverflow.com/a/37087295/1777662
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 02:01:27 2019 UTC