php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63742 Stack tree DOMDocument::registerNodeClass incorrect
Submitted: 2012-12-11 16:50 UTC Modified: 2019-09-23 07:15 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: giso at connectholland dot nl Assigned: beberlei (profile)
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.3 OS: Linux / Debian
Private report: No CVE-ID: None
 [2012-12-11 16:50 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-11 17:02 UTC] giso at connectholland dot nl
-PHP Version: 5.3.19 +PHP Version: 5.3.3
 [2012-12-11 17:02 UTC] giso at connectholland dot nl
Add 

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

to the reproduction script
 [2019-09-22 22:14 UTC] beberlei@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: beberlei
 [2019-09-22 22:14 UTC] 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.
 [2019-09-23 07:15 UTC] giso at connectholland dot nl
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC