From da82ebaca864afcf60a0fb25f39b505e0781d26e Mon Sep 17 00:00:00 2001 From: Witchakorn Kamolpornwijit Date: Thu, 3 Apr 2014 23:09:09 +0000 Subject: [PATCH] Return same c_DOMElement object when calling getElementById multiple times --- hphp/runtime/ext/ext_domdocument.cpp | 4 ++++ hphp/test/slow/dom_document/2109.php | 12 ++++++++++++ hphp/test/slow/dom_document/2109.php.expect | 1 + 3 files changed, 17 insertions(+) create mode 100644 hphp/test/slow/dom_document/2109.php create mode 100644 hphp/test/slow/dom_document/2109.php.expect diff --git a/hphp/runtime/ext/ext_domdocument.cpp b/hphp/runtime/ext/ext_domdocument.cpp index 31e43f6560f1f..e99dd4231aa0f 100644 --- a/hphp/runtime/ext/ext_domdocument.cpp +++ b/hphp/runtime/ext/ext_domdocument.cpp @@ -3325,10 +3325,14 @@ Variant c_DOMDocument::t_createtextnode(const String& data) { Variant c_DOMDocument::t_getelementbyid(const String& elementid) { xmlDocPtr docp = (xmlDocPtr)m_node; xmlAttrPtr attrp = xmlGetID(docp, (xmlChar*)elementid.data()); + if (attrp && attrp->_private) { + return static_cast(attrp->_private); + } if (attrp && attrp->parent) { c_DOMElement *ret = NEWOBJ(c_DOMElement)(); ret->m_doc = this; ret->m_node = attrp->parent; + attrp->_private = static_cast(ret); return ret; } return uninit_null(); diff --git a/hphp/test/slow/dom_document/2109.php b/hphp/test/slow/dom_document/2109.php new file mode 100644 index 0000000000000..b4a1f49a4728c --- /dev/null +++ b/hphp/test/slow/dom_document/2109.php @@ -0,0 +1,12 @@ +loadHTML(' + +
+
+
+
+'); +$form1 = $dom->getElementById('form_2'); +$form2 = $dom->getElementById('form_2'); +var_dump(spl_object_hash($form1) == spl_object_hash($form2)); diff --git a/hphp/test/slow/dom_document/2109.php.expect b/hphp/test/slow/dom_document/2109.php.expect new file mode 100644 index 0000000000000..ea5b1fdc3c0f5 --- /dev/null +++ b/hphp/test/slow/dom_document/2109.php.expect @@ -0,0 +1 @@ +bool(true)