Doc #61797 [PATCH]: DOMNode::appendChild doesn't increment refcount
| From: | krakjoe@php.net | Date: | Mon, 02 Dec 2013 19:43:25 +0000 |
| Subject: | Doc #61797 [PATCH]: DOMNode::appendChild doesn't increment refcount | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10666@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61797&edit=1
ID: 61797
Patch added by: krakjoe@php.net
Reported by: kuba dot brecka at gmail dot com
Summary: DOMNode::appendChild doesn't increment refcount
Status: Open
Type: Documentation Problem
Package: DOM XML related
Operating System: Windows, Linux
PHP Version: 5.4.0
Block user comment: N
Private report: N
New Comment:
The following patch has been added/updated:
Patch Name: dom_node_append_child.patch
Revision: 1386013405
URL: https://bugs.php.net/patch-display.php?bug=61797&patch=dom_node_append_child.patch&revision=1386013405
Previous Comments:
------------------------------------------------------------------------
[2012-04-26 13:46:48] kuba dot brecka at gmail dot com
Well, registerNodeClass solves it. But I still believe that without it, the
behaviour should not depend on the refcount of the object you are trying to use in
DOM. It should at least emit a warning or an exception, that you are using an
object, which has not beed registered.
Anyway, the need to use registerNodeClass should be mentioned in the docs, at
least in appendChild.
------------------------------------------------------------------------
[2012-04-26 13:27:54] maarten@php.net
Shouldn't you just use registerNodeClass() ?
See http://3v4l.org/E88Nk for a modified script
------------------------------------------------------------------------
[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