|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-05-24 00:27 UTC] rrichards@php.net
[2004-05-24 00:54 UTC] bart at mediawave dot nl
[2004-05-24 01:56 UTC] rrichards@php.net
[2004-05-26 16:23 UTC] bart at mediawave dot nl
[2004-05-27 11:40 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 17:00:01 2025 UTC |
Description: ------------ Setting custom variables in DOM objects like: $domNode->customVar = 'myValue'; Are inconsistently lost when working with a dom. Reproduce code: --------------- <?php class myclass { function run() { $xp = new domxpath($this->dom); $widths = $xp->query('//td/@width'); foreach ($widths as $width) { echo $this->name.' 1: width->myVar value:'.$width->myVar.'<br>'; $width->myVar = '1'; } $tds = $this->dom->getElementsByTagName('td'); foreach ($tds as $td) { echo $this->name.' 2: td->myVar value:'.$td->myVar.'<br>'; $td->myVar = '1'; } echo '<br>'; $tds = $this->dom->getElementsByTagName('td'); foreach ($tds as $td) { if ($width = $td->getAttributeNode('width')) { echo $this->name.' 3: width->myVar value:'.$width->myVar.'<br>'; $width->myVar = '2'; } echo $this->name.' 4: td->myVar value:'.$td->myVar.'<br>'; $td->myVar = '2'; } echo '<br>'; } } $xml = '<root> <tr><td width="40">hello</td><td width="40">world</td></tr> <tr><td>Just one TD</td></tr> <tr><td>TD with <b>mixed</b> <i>content</i></td></tr> </root>'; $dom = new DomDocument; $dom->loadXML($xml); $firstInstance = new myclass; $firstInstance->name = 'firstInstance'; $firstInstance->dom = $dom; $firstInstance->run(); $secondInstance = new myclass; $secondInstance->name = 'secondInstance'; $secondInstance->dom = $firstInstance->dom; $secondInstance->run(); ?> Expected result: ---------------- firstInstance 1: width->myVar value: firstInstance 1: width->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 3: width->myVar value:1 firstInstance 4: td->myVar value:1 firstInstance 3: width->myVar value:1 firstInstance 4: td->myVar value:1 firstInstance 4: td->myVar value:1 firstInstance 4: td->myVar value:1 secondInstance 1: width->myVar value:2 secondInstance 1: width->myVar value:2 secondInstance 2: td->myVar value:2 secondInstance 2: td->myVar value:2 secondInstance 2: td->myVar value:2 secondInstance 2: td->myVar value:2 secondInstance 3: width->myVar value:1 secondInstance 4: td->myVar value:1 secondInstance 3: width->myVar value:1 secondInstance 4: td->myVar value:1 secondInstance 4: td->myVar value:1 secondInstance 4: td->myVar value:1 Actual result: -------------- firstInstance 1: width->myVar value: firstInstance 1: width->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 2: td->myVar value: firstInstance 3: width->myVar value:1 firstInstance 4: td->myVar value: firstInstance 3: width->myVar value:1 firstInstance 4: td->myVar value: firstInstance 4: td->myVar value: firstInstance 4: td->myVar value: secondInstance 1: width->myVar value: secondInstance 1: width->myVar value: secondInstance 2: td->myVar value: secondInstance 2: td->myVar value: secondInstance 2: td->myVar value: secondInstance 2: td->myVar value: secondInstance 3: width->myVar value:1 secondInstance 4: td->myVar value: secondInstance 3: width->myVar value:1 secondInstance 4: td->myVar value: secondInstance 4: td->myVar value: secondInstance 4: td->myVar value: