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

Patches

Pull Requests

History

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

And I don't think it will be addressed in a future version of PHP
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC