From:             bart at mediawave dot nl
Operating system: Windows XP
PHP version:      5.0.0RC2
PHP Bug Type:     DOM XML related
Bug description:  DOM object custom variables get lost

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:

-- 
Edit bug report at http://bugs.php.net/?id=28473&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28473&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28473&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28473&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28473&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28473&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28473&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28473&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28473&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28473&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28473&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28473&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28473&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28473&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28473&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28473&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28473&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28473&r=float

Reply via email to