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

 ID:                 52640
 User updated by:    ken at smallboxcms dot com
 Reported by:        ken at smallboxcms dot com
 Summary:            Odd Garbage collection Behaviour with Dom Node
 Status:             Bogus
 Type:               Bug
 Package:            DOM XML related
 Operating System:   Linux
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

Well, to my way of thinking the the XML document is expressed as a PHP
object so it should behave as one in every respect. Here is an example
where there is a distinct difference in that behaviour, one that would
be unexpected by a PHP programmer who is not intimately acquainted with
PHP's internals. I am fairly certain that this difference is
undocumented. 



Here is another example which more clearly illustrates the problem. 



<?php



$blah = new stdClass;

function humbug()

{

/* Behaviour changes when uncommented. Think this is a GC bug.

    global $node;

*/



    global $blah;

    $doc = new domDocument('1.0', 'utf-8');

    $blah->doc = $doc;

    $node = $doc->createElement('node');

    $doc->appendChild($node);



    $node->foo = true;



    $obj = new stdClass;

    $blah->obj = $obj;

    $obj->child = new stdClass;

    $obj->child->foo = true;



    echo "Why is this set: ".$blah->doc->firstChild->foo."<BR>";

}



humbug();

echo "When this is not set: ".$blah->doc->firstChild->foo."<BR>\n";

echo "This is Set: ".$blah->obj->child->foo."<BR>\n";







?>


Previous Comments:
------------------------------------------------------------------------
[2011-02-17 22:56:39] rricha...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

DOM objects are just wrappers to underlying libxml2 structures and
unless directly 

referenced, i.e. $blah->node = $node, the $node object is no longer
referenced 

outside of the function. Appending the node appends the libxml2 node
structure to 

the underlying xml tree, does nothing in respect to the DOM object
wrapper.

------------------------------------------------------------------------
[2010-08-19 00:32:30] ken at smallboxcms dot com

Description:
------------
Variables added to dom nodes are later unset. This behaviour does not
appear to happen with other types of PHP objects. 

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



$blah = new stdClass;

function humbug()

{

/* Behaviour changes when uncommented. Think this is a GC bug.

    global $node;

*/



    global $blah;

    $doc = new domDocument('1.0', 'utf-8');

    $blah->doc = $doc;

    $node = $doc->createElement('node');

    $doc->appendChild($node);



    $node->foo = true;



    $obj = new stdClass;

    $blah->obj = $obj;

    $obj->child = new stdClass;

    $obj->child->foo = true;

}



humbug();

echo "Should be set: ".$blah->doc->firstChild->foo."<BR>\n";

echo "Is Set: ".$blah->obj->child->foo."<BR>\n";



?>

Expected result:
----------------
I would expect that $blah->doc->firstChild->foo would be set after the
function call. 



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



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

Reply via email to