|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30861 DOMDocument::importNode() issue with extended classes
Submitted: 2004-11-22 14:36 UTC Modified: 2004-11-22 16:25 UTC
From: jason at amp-design dot net Assigned:
Status: Wont fix Package: *XML functions
PHP Version: 5.0.2 OS: Win2003 / CentOS / MacOS X
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: jason at amp-design dot net
New email:
PHP Version: OS:


 [2004-11-22 14:36 UTC] jason at amp-design dot net
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:

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();
$root = $doc->documentElement;

/* Append new FooBar into main document */
$BarObj = new Bar('EatMoreFoo');
/* 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);

/* 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 ( )


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-22 16:25 UTC]
Doesn't work by design...

And I don't think it will be addressed in a future version of PHP
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 12:01:23 2020 UTC