From:             
Operating system: Windows, Linux
PHP version:      5.4.0
Package:          DOM XML related
Bug Type:         Bug
Bug description:DOMNode::appendChild doesn't increment refcount

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 bug report at https://bugs.php.net/bug.php?id=61797&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61797&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61797&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61797&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61797&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61797&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61797&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61797&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61797&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61797&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61797&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61797&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61797&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61797&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61797&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61797&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61797&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61797&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61797&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61797&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61797&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61797&r=mysqlcfg

Reply via email to