Skip to content

Commit

Permalink
Return same c_DOMElement object when calling getElementById multiple …
Browse files Browse the repository at this point in the history
…times

Should fix #2109
Closes #2314

Reviewed By: @fredemmott

Differential Revision: D1260361
  • Loading branch information
chalet16 authored and sgolemon committed Apr 8, 2014
1 parent 507304c commit b568bf9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hphp/runtime/ext/ext_domdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3337,10 +3337,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<c_DOMElement*>(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<void*>(ret);
return ret;
}
return uninit_null();
Expand Down
12 changes: 12 additions & 0 deletions hphp/test/slow/dom_document/2109.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$dom = new \DOMDocument();
$dom->loadHTML('
<html>
<form id="form-1" action="" method="POST">
</form>
<form id="form_2" action="" method="POST">
</form>
</html>');
$form1 = $dom->getElementById('form_2');
$form2 = $dom->getElementById('form_2');
var_dump(spl_object_hash($form1) === spl_object_hash($form2));
1 change: 1 addition & 0 deletions hphp/test/slow/dom_document/2109.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool(true)

0 comments on commit b568bf9

Please sign in to comment.