Bug #63742 [Nab]: Stack tree DOMDocument::registerNodeClass incorrect

From: Date: Mon, 23 Sep 2019 07:15:43 +0000
Subject: Bug #63742 [Nab]: Stack tree DOMDocument::registerNodeClass incorrect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222885@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63742&edit=1

 ID:                 63742
 User updated by:    giso at connectholland dot nl
 Reported by:        giso at connectholland dot nl
 Summary:            Stack tree DOMDocument::registerNodeClass incorrect
 Status:             Not a bug
 Type:               Bug
 Package:            DOM XML related
 Operating System:   Linux / Debian
 PHP Version:        5.3.3
 Assigned To:        beberlei
 Block user comment: N
 Private report:     N

 New Comment:

I think your solution should work now. At the time of reporting traits did not exists. Thanks for
having taken time to look into this. Close this if you like.


Previous Comments:
------------------------------------------------------------------------
[2019-09-22 22:14:12] beberlei@php.net

This is not a bug, because DOMElement extends DOMNode, not MyDOMNode. You can't change the
existing class hierachy at runtime. 

To fix this, use "traits" to import the MyDOMNode behaviors into MyDOMElement.

------------------------------------------------------------------------
[2012-12-11 17:02:58] giso at connectholland dot nl

Add 

class MyDOMNode extends DOMNode {}
class MyDOMElement extends DOMElement {}

to the reproduction script

------------------------------------------------------------------------
[2012-12-11 16:50:30] giso at connectholland dot nl

Description:
------------
When using DOMDocument::registerNodeClass for both DOMElement and DOMNode a 
DOMElement does nog get to be a child of the registered DOMNode class

Test script:
---------------
<?php
class MyDOMDocument extends DOMDocument {
	public function __construct($version = null, $encoding = null) {
		parent::__construct($version, $encoding);
		
		$this->registerNodeClass("DOMNode", "MyDOMNode");
		$this->registerNodeClass("DOMElement", "MyDOMElement");
        }
}

$dom = new MyDOMDocument();
$dom->loadXML("<root/>");

$parent_class_names = array();
$parent_class_name = get_class($dom->documentElement);
do {
    $parent_class_names[] = $parent_class_name;
} while($parent_class_name = get_parent_class($parent_class_name));

var_dump($parent_class_names);
?>

Expected result:
----------------
array (size=4)
  0 => string 'MyDOMElement' (length=12)
  1 => string 'DOMElement' (length=10)
  2 => string 'MyDOMNode' (length=9)
  3 => string 'DOMNode' (length=7)


Actual result:
--------------
array (size=3)
  0 => string 'MyDOMElement' (length=12)
  1 => string 'DOMElement' (length=10)
  2 => string 'DOMNode' (length=7)



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=63742&edit=1


Thread (4 messages)

« previous php.bugs (#222885) next »