Bug #67459 [Nab]: DOMDocument memory hanldling
| From: | goetas at gmail dot com | Date: | Mon, 23 Sep 2019 06:15:19 +0000 |
| Subject: | Bug #67459 [Nab]: DOMDocument memory hanldling | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222884@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
User updated by: goetas at gmail dot com
Reported by: goetas at gmail dot com
Summary: DOMDocument memory hanldling
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: ubuntu
PHP Version: 5.5.13
Assigned To: beberlei
Block user comment: N
Private report: N
New Comment:
Hi ,
thanks for the update on this!
I can understand that this is the internal behavior (probably connected on how the integration with
libxml is done), but it is not intuitive and different from the current OO model exposed by the PHP
language.
I can understand that the fix might be not easy, but it should then at least documented that the
DOMDocument object might nof follow fully the classica OO behavior.
Previous Comments:
------------------------------------------------------------------------
[2019-09-22 22:26:13] beberlei@php.net
$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.
------------------------------------------------------------------------
[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