Bug #71872 [Opn]: PHP registerNodeClass and reusing variable names
| From: | jacksonpauls at gmail dot com | Date: | Wed, 11 May 2016 14:57:29 +0000 |
| Subject: | Bug #71872 [Opn]: PHP registerNodeClass and reusing variable names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201017@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71872&edit=1
ID: 71872
User updated by: jacksonpauls at gmail dot com
Reported by: jacksonpauls at gmail dot com
Summary: PHP registerNodeClass and reusing variable names
Status: Open
Type: Bug
Package: DOM XML related
Operating System: Linux - Fedora 23
-PHP Version: 7.0.4
+PHP Version: 7.0.6
Block user comment: N
Private report: N
New Comment:
There's now a detailed explanation of why this happens here: http://stackoverflow.com/a/37087295/1777662
Previous Comments:
------------------------------------------------------------------------
[2016-03-21 16:29:16] 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"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71872&edit=1