note 58436 added to function.dom-domdocument-importnode
| From: | TJ | Date: | Fri, 04 Nov 2005 09:15:29 +0000 |
| Subject: | note 58436 added to function.dom-domdocument-importnode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98054@lists.php.net to get a copy of this message | ||
Beware if you're working with classes you've extended from DOMNode, DOMElement, etc.
Calling importNode() with an object of your derived class will result in the copy being an instance
of the DOM super class.
You will *not* get a copy of the derived class or any of its properties or methods.
For example:
<?
class extDOMElement extends DOMElement {
function __construct($name, $value='', $namespaceURI=null) {
parent::__construct($name, $value, $namespaceURI);
}
}
class extDOMDocument extends DOMDocument {
// over-ride DOMDocument->createElement()
public function createElement($name, $value) {
// intention is to set extDOMElement->ownerDocument property
$orphan = new extDOMElement($name, $value);
$adopt = $this->importNode($orphan, true);
/* at this point $adopt is expected to be an instance of
* extDOMElement with ownerDocument property set
*/
return $adopt; // but $adopt is only a DOMElement
}
}
$doc = new extDOMDocument();
$el = $doc->createElement('tagName');
echo 'Element instanceof '.get_class($el);
?>
Will display "Element instanceof DOMElement" rather than the expected
"extDOMElement"
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-importnode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58436
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58436&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58436&report=yes
Search -- http://master.php.net/manage/user-notes.php