From:             jason at amp-design dot net
Operating system: Win2003 / CentOS / MacOS X
PHP version:      5.0.2
PHP Bug Type:     *XML functions
Bug description:  DOMDocument::importNode() issue with extended classes

Description:
------------
This relates to bug ID 29092 that I posted, however this makes it hard to
extend use extended classes for DOMnodes and  move them about from
document to document without loosing the object type. If there is any
other solution or work about, I would be grateful. Is this something that
is not fixable, or will it be addressed in future versions of PHP?

DOMNode::cloneNode also suffers this as well, from what I remember.

Reproduce code:
---------------
<?php

class Bar extends DOMElement {
        public $foo = 'FooBar happens';
}

/* Load of nonsense XML */
$xml = '<root><foo><bar><foo2 /><foo2 />Foo bar Foo bar Foo bar<foo2
/></bar><bar2 /></foo></root>';
// Yea I know i should use the DOMimplementation factory method here.
$doc = new DOMDocument();
$doc->loadXML($xml);
$root = $doc->documentElement;

/* Append new FooBar into main document */
$BarObj = new Bar('EatMoreFoo');
$root->appendChild($BarObj);
/* Assign FooBar */
$BarObj->foo = 'FooBar Happens to change';
$BarObj->setAttribute('id', 'dfdf');

/* make another document */
$doc2 = new DOMDocument();
/* import our other document's root. Note here the upcasting to DOMelement
happens */
$root2 = $doc2->importNode($root, true);
$doc2->appendChild($root2);

/* PooPoo happens here. 
 * Node is copied and thus no PHP reference to the node, 
 * hence upcasting of object occur */ 
$x_path_cack = new DOMXPath($doc2);
$list_of_cack = $x_path_cack->query('//EatMoreFoo');
print_R($list_of_cack->item(0)); // Should echo FooBar Object()

?>

Expected result:
----------------
FooFar Object ( )

Actual result:
--------------
DOMElement Object ( )

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

Reply via email to