Edit report at http://bugs.php.net/bug.php?id=51462&edit=1

 ID:               51462
 Updated by:       rricha...@php.net
 Reported by:      pahan at hubbitus dot info
 Summary:          Extending DOM classes work only if copy of object
                   present
-Status:           Open
+Status:           Wont fix
 Type:             Bug
 Package:          DOM XML related
 Operating System: Linux
 PHP Version:      5.3.2

 New Comment:

The tree does not maintain object state. If you are only looking for
your own 

classtypes to be returned by the DOM methods/properties then use 

registerNodeClass() to register the types.


Previous Comments:
------------------------------------------------------------------------
[2010-04-02 12:51:04] pahan at hubbitus dot info

Description:
------------
Extending some DOM classes (f.e. DOMDOcument, DOMElement I think others,
but not 

tested) work. But when such elemenmt appended to the document,
additional 

information lost. Meantime, when copy of object saved alsewere, all work
as 

expected.



First mention of this bug and initial workaround in comment 

http://php.net/manual/tr/book.dom.php#80613 by ryoroxdahouse at hotmail
dot com.



I make automattical workaround like ( 

http://hinikato.blogspot.com/2009/10/domelement.html?

showComment=1270202266600#c284093039037001302 ):

class MyElement extends DOMElement

{

public function __construct($name, $value = null, $uri = null) {

parent::__construct($name, $value, $uri);

$GLOBALS['PHP_HACK_DOM_ELEMENT'][spl_object_hash($this)] = $this;
//Note, 

reference is not enough :(

}



public function __destruct() {

unset($GLOBALS['PHP_HACK_DOM_ELEMENT'][spl_object_hash($this)]);

}

}



But as we need object copy, not just reference it requires double of
memmory!

Test script:
---------------
<?

class MyElement extends DOMElement{}

$doc = new DOMDocument();

$doc->appendChild(new MyElement('test'));

var_dump($doc->documentElement);

?>

Expected result:
----------------
object(MyElement)#4 (0) { } 

Actual result:
--------------
object(DOMElement)#4 (0) { }


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



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

Reply via email to