Bug #67459 [Opn->Nab]: DOMDocument memory hanldling

From: Date: Sun, 22 Sep 2019 22:26:13 +0000
Subject: Bug #67459 [Opn->Nab]: DOMDocument memory hanldling
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222875@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67459&edit=1

 ID:                 67459
 Updated by:         beberlei@php.net
 Reported by:        goetas at gmail dot com
 Summary:            DOMDocument memory hanldling
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            DOM XML related
 Operating System:   ubuntu
 PHP Version:        5.5.13
-Assigned To:        
+Assigned To:        beberlei
 Block user comment: N
 Private report:     N

 New Comment:

$document->documentElement is not like a public property, but like a magic __set/get property
that accepts the element and transaltes it into its internal structure, then "looses" the
original element set as argument.

This means, accessing $document->documentElement creates a new DOMElement on the fly.

Hence reference comparisons will not really work with any DOM nodes at all.


Previous Comments:
------------------------------------------------------------------------
[2014-06-17 06:45:09] goetas at gmail dot com

Description:
------------
Strange object allocation issue, maybe related to PHP/LIBXML memory handling.

I've supposed that PHP releases the object associated to $root when I unset it (even if this
object can be reached through $dom->documentElement).

Later, when I create the $ele element, it takes the same memory position of $root.


LIBXML version 2.7.8

Test script:
---------------
$dom = new \DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement('root');
$dom->appendChild($root);

$h1 = spl_object_hash($root);
$h2 = spl_object_hash($dom->documentElement);

var_dump($root === $dom->documentElement); // true, OK
var_dump($h1 === $h2); // true, OK

unset($root);

$ele = $dom->createElement('ele');

$h3 = spl_object_hash($ele);
$h4 = spl_object_hash($dom->documentElement);

var_dump($h1 === $h3); // expected to be false, but actually true
var_dump($h1 === $h4); // expected to be true, but actually false


Expected result:
----------------
bool(true)
bool(true)
bool(false)
bool(true)

Actual result:
--------------
bool(true)
bool(true)
bool(true)
bool(false)



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



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


Thread (3 messages)

« previous php.bugs (#222875) next »