Edit report at https://bugs.php.net/bug.php?id=61797&edit=1
ID: 61797 User updated by: kuba dot brecka at gmail dot com Reported by: kuba dot brecka at gmail dot com Summary: DOMNode::appendChild doesn't increment refcount -Status: Feedback +Status: Open Type: Bug Package: DOM XML related Operating System: Windows, Linux PHP Version: 5.4.0 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2012-04-26 13:27:54] maar...@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