Bug #71872 [NEW]: PHP registerNodeClass and reusing variable names

From: Date: Mon, 21 Mar 2016 16:29:21 +0000
Subject: Bug #71872 [NEW]: PHP registerNodeClass and reusing variable names
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200002@lists.php.net to get a copy of this message
From: jacksonpauls at gmail dot com Operating system: Linux - Fedora 23 PHP version: 7.0.4 Package: DOM XML related Bug Type: Bug Bug description:PHP registerNodeClass and reusing variable names 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 bug report at https://bugs.php.net/bug.php?id=71872&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71872&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71872&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71872&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71872&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71872&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71872&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71872&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71872&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71872&r=support Expected behavior: https://bugs.php.net/fix.php?id=71872&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71872&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71872&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71872&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71872&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71872&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71872&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71872&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71872&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71872&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71872&r=mysqlcfg

« previous php.bugs (#200002) next »