diff --git a/ext/dom/element.c b/ext/dom/element.c index bed7cfbf966..a5d27bd8f09 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -1555,7 +1555,7 @@ PHP_METHOD(DOMElement, toggleAttribute) } /* Step 2 */ - if (thisp->doc->type == XML_HTML_DOCUMENT_NODE && (thisp->ns == NULL || xmlStrEqual(thisp->ns->href, (const xmlChar *) "http://www.w3.org/1999/xhtml"))) { + if (thisp->doc != NULL && thisp->doc->type == XML_HTML_DOCUMENT_NODE && (thisp->ns == NULL || xmlStrEqual(thisp->ns->href, (const xmlChar *) "http://www.w3.org/1999/xhtml"))) { qname_tmp = zend_str_tolower_dup_ex(qname, qname_length); if (qname_tmp != NULL) { qname = qname_tmp; diff --git a/ext/dom/tests/DOMElement_toggleAttribute_without_document.phpt b/ext/dom/tests/DOMElement_toggleAttribute_without_document.phpt new file mode 100644 index 00000000000..ecd930b487c --- /dev/null +++ b/ext/dom/tests/DOMElement_toggleAttribute_without_document.phpt @@ -0,0 +1,17 @@ +--TEST-- +DOMElement::toggleAttribute() without a document +--EXTENSIONS-- +dom +--FILE-- +toggleAttribute('foo', true); + +$dom = new DOMDocument; +$element = $dom->importNode($element, true); +echo $dom->saveXML($element), "\n"; + +?> +--EXPECT-- +