|  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
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
30 - 23 = ?
Subscribe to this entry?

 [2016-03-21 16:29 UTC] jacksonpauls at gmail dot com
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:

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

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

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

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

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

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

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"


Add a Patch

Pull Requests

Add a Pull Request


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:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun May 31 21:01:25 2020 UTC