php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70026 Instances of DOMDocument lose derived class information when refcount low
Submitted: 2015-07-08 15:18 UTC Modified: 2019-09-22 22:35 UTC
From: dexen dot devries at gmail dot com Assigned: beberlei (profile)
Status: Wont fix Package: DOM XML related
PHP Version: 5.6.10 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-07-08 15:18 UTC] dexen dot devries at gmail dot com
Description:
------------
DOMXPath instances mis-handle instances of classes derived from DOMDocument in some cases, as accessible via $document property. Instances of classes derived from DOMDocument can suffer loss of information, both on derived class type and properties of the derived class.

Both derived class name and properties of instance of the derived class are lost.

Problems seems to be related to refcount going down to zero; can be reliably triggered both by returning instance of DOMDocument derived class from function, and by manually unset()ting all variables refering to the instance of class derived from DOMDocument.

Test script:
---------------
http://pastebin.ca/3051231

Expected result:
----------------
Instance of DOMXPath should hold the original DOMDocument instances in $document property.

Actual result:
--------------
Instance of DOMXPath holds some sort of copy of DOMDocument instance in $document, if refcount goes to zero, resulting in loss of both derived class information, and properties of the derived class.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-10 16:04 UTC] cmb@php.net
That seems to be related to bug #61797.
 [2019-09-22 22:35 UTC] beberlei@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: beberlei
 [2019-09-22 22:35 UTC] beberlei@php.net
This is not a bug. You should see the document property as using "magic" __get and creating new DOMDocument objects as it needs them based on the underlying libxml DOM structure that is managed. ext/dom does not guarantee reference equality of nodes.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 19 22:03:37 2021 UTC