diff --git a/NEWS b/NEWS
index 52aa8b3bcf0..989e53f2850 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP NEWS
(nielsdos)
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
. Fix empty argument cases for DOMParentNode methods. (nielsdos)
+ . Fixed bug GH-11791 (Wrong default value of DOMDocument::xmlStandalone).
+ (nielsdos)
- FFI:
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 71e12b6e7a9..e0eeb80fcb7 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -187,7 +187,7 @@ int dom_document_standalone_read(dom_object *obj, zval *retval)
return FAILURE;
}
- ZVAL_BOOL(retval, docp->standalone);
+ ZVAL_BOOL(retval, docp->standalone > 0);
return SUCCESS;
}
diff --git a/ext/dom/tests/domobject_debug_handler.phpt b/ext/dom/tests/domobject_debug_handler.phpt
index 8dbaa61a165..51750710545 100644
--- a/ext/dom/tests/domobject_debug_handler.phpt
+++ b/ext/dom/tests/domobject_debug_handler.phpt
@@ -12,53 +12,89 @@ XML;
$d = new domdocument;
$d->dynamicProperty = new stdclass;
$d->loadXML($xml);
-print_r($d);
+var_dump($d);
?>
---EXPECTF--
-DOMDocument Object
-(
- [config] =>
- [dynamicProperty] => stdClass Object
- (
- )
-
- [doctype] =>
- [implementation] => (object value omitted)
- [documentElement] => (object value omitted)
- [actualEncoding] =>
- [encoding] =>
- [xmlEncoding] =>
- [standalone] => 1
- [xmlStandalone] => 1
- [version] => 1.0
- [xmlVersion] => 1.0
- [strictErrorChecking] => 1
- [documentURI] => %s
- [formatOutput] =>
- [validateOnParse] =>
- [resolveExternals] =>
- [preserveWhiteSpace] => 1
- [recover] =>
- [substituteEntities] =>
- [firstElementChild] => (object value omitted)
- [lastElementChild] => (object value omitted)
- [childElementCount] => 1
- [nodeName] => #document
- [nodeValue] =>
- [nodeType] => 9
- [parentNode] =>
- [childNodes] => (object value omitted)
- [firstChild] => (object value omitted)
- [lastChild] => (object value omitted)
- [previousSibling] =>
- [nextSibling] =>
- [attributes] =>
- [ownerDocument] =>
- [namespaceURI] =>
- [prefix] =>
- [localName] =>
- [baseURI] => %s
- [textContent] =>
+--EXPECT--
+object(DOMDocument)#1 (39) {
+ ["config"]=>
+ NULL
+ ["dynamicProperty"]=>
+ object(stdClass)#2 (0) {
+ }
+ ["doctype"]=>
+ NULL
+ ["implementation"]=>
+ string(22) "(object value omitted)"
+ ["documentElement"]=>
+ string(22) "(object value omitted)"
+ ["actualEncoding"]=>
+ NULL
+ ["encoding"]=>
+ NULL
+ ["xmlEncoding"]=>
+ NULL
+ ["standalone"]=>
+ bool(false)
+ ["xmlStandalone"]=>
+ bool(false)
+ ["version"]=>
+ string(3) "1.0"
+ ["xmlVersion"]=>
+ string(3) "1.0"
+ ["strictErrorChecking"]=>
+ bool(true)
+ ["documentURI"]=>
+ string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
+ ["formatOutput"]=>
+ bool(false)
+ ["validateOnParse"]=>
+ bool(false)
+ ["resolveExternals"]=>
+ bool(false)
+ ["preserveWhiteSpace"]=>
+ bool(true)
+ ["recover"]=>
+ bool(false)
+ ["substituteEntities"]=>
+ bool(false)
+ ["firstElementChild"]=>
+ string(22) "(object value omitted)"
+ ["lastElementChild"]=>
+ string(22) "(object value omitted)"
+ ["childElementCount"]=>
+ int(1)
+ ["nodeName"]=>
+ string(9) "#document"
+ ["nodeValue"]=>
+ NULL
+ ["nodeType"]=>
+ int(9)
+ ["parentNode"]=>
+ NULL
+ ["childNodes"]=>
+ string(22) "(object value omitted)"
+ ["firstChild"]=>
+ string(22) "(object value omitted)"
+ ["lastChild"]=>
+ string(22) "(object value omitted)"
+ ["previousSibling"]=>
+ NULL
+ ["nextSibling"]=>
+ NULL
+ ["attributes"]=>
+ NULL
+ ["ownerDocument"]=>
+ NULL
+ ["namespaceURI"]=>
+ NULL
+ ["prefix"]=>
+ string(0) ""
+ ["localName"]=>
+ NULL
+ ["baseURI"]=>
+ string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
+ ["textContent"]=>
+ string(12) "
foobar
-
-)
+"
+}
diff --git a/ext/dom/tests/gh11791.phpt b/ext/dom/tests/gh11791.phpt
new file mode 100644
index 00000000000..22d94b51312
--- /dev/null
+++ b/ext/dom/tests/gh11791.phpt
@@ -0,0 +1,39 @@
+--TEST--
+GH-11791 (Wrong default value of DOMDocument.xmlStandalone)
+--EXTENSIONS--
+dom
+--FILE--
+loadXML('');
+var_dump($doc->xmlStandalone);
+$doc->xmlStandalone = true;
+var_dump($doc->xmlStandalone);
+
+$doc = new DOMDocument();
+$doc->loadXML('');
+var_dump($doc->xmlStandalone);
+$doc->xmlStandalone = true;
+var_dump($doc->xmlStandalone);
+
+$doc = new DOMDocument();
+$doc->loadXML('');
+var_dump($doc->xmlStandalone);
+$doc->xmlStandalone = true;
+var_dump($doc->xmlStandalone);
+
+$doc = new DOMDocument();
+$doc->loadXML('');
+var_dump($doc->xmlStandalone);
+$doc->xmlStandalone = false;
+var_dump($doc->xmlStandalone);
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(false)