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

From: Date: Sun, 22 Sep 2019 22:14:12 +0000
Subject: Bug #63742 [Opn->Nab]: Stack tree DOMDocument::registerNodeClass incorrect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222874@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
 Updated by:         beberlei@php.net
 Reported by:        giso at connectholland dot nl
 Summary:            Stack tree DOMDocument::registerNodeClass incorrect
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            DOM XML related
 Operating System:   Linux / Debian
 PHP Version:        5.3.3
-Assigned To:        
+Assigned To:        beberlei
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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 (#222874) next »