Bug #61797 [Opn->Fbk]: DOMNode::appendChild doesn't increment refcount
Edit report at https://bugs.php.net/bug.php?id=61797&edit=1
ID: 61797
Updated by: maarten@php.net
Reported by: kuba dot brecka at gmail dot com
Summary: DOMNode::appendChild doesn't increment refcount
-Status: Open
+Status: Feedback
Type: Bug
Package: DOM XML related
Operating System: Windows, Linux
PHP Version: 5.4.0
Block user comment: N
Private report: N
New Comment:
Shouldn't you just use registerNodeClass() ?
See http://3v4l.org/E88Nk for a modified script
Previous Comments:
------------------------------------------------------------------------
[2012-04-21 10:37:03] kuba dot brecka at gmail dot com
Description:
------------
When I create a DOM element and I add it via DOMDocument->appendChild, it seems
that the refcount to that object is not increased. This causes the appended child
to be deallocated if there are no other references. It also causes some funky
behaviour, because the freed object can still be accesssed (doesn't) crash, but
it seems to be of different type. Don't know the cause, maybe the memory gets
either reused to create another object.
I created a simple test case that proves and reproduces this buggy behaviour,
AFAIK all PHP versions are affected, I tested 5.4.0 on Windows.
Test script:
---------------
class MyElement extends DOMElement { }
// #1 - okay
$dom = new DOMDocument();
$e = new MyElement("e");
$dom->appendChild($e);
echo get_class($dom->childNodes->item(0)) . "\n";
// #2 - wrong
$dom = new DOMDocument();
$dom->appendChild(new MyElement("e"));
echo get_class($dom->childNodes->item(0)) . "\n";
// #3 - wrong
$dom = new DOMDocument();
$e = new MyElement("e");
$dom->appendChild($e);
$e = null;
echo get_class($dom->childNodes->item(0)) . "\n";
Expected result:
----------------
MyElement
MyElement
MyElement
Actual result:
--------------
MyElement
DOMElement
DOMElement
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61797&edit=1
Thread (10 messages)