Commit 793f0ee6889 for php

commit 793f0ee68899cdcf5633a804d992029e431c5477
Author: Tomasz Kowalczyk <tomasz@kowalczyk.cc>
Date:   Fri Nov 27 21:41:03 2026 +0100

    ext/dom: Dom\Element::setIdAttributeNS() rejects null for $namespace

    Dom\Element::setIdAttributeNS() now has its own method entry that parses
    $namespace as a nullable string, so null means no namespace, as the stub
    declares. Like the other *NS methods of Dom\Element, it also treats "" as no
    namespace. Before, null threw a TypeError in strict mode and was otherwise
    coerced to "" with a deprecation, and "" matched only an attribute whose
    namespace is the empty string, for example a DTD default attribute parsed
    with LIBXML_DTDATTR or an attribute of an imported legacy node.
    DOMElement::setIdAttributeNS() is unchanged.

    Fix GH-25998
    Close GH-25999

diff --git a/NEWS b/NEWS
index cb15756360e..3ce05cf1546 100644
--- a/NEWS
+++ b/NEWS
@@ -87,6 +87,8 @@ PHP                                                                        NEWS
     crash at document teardown). (Ian Mattas)
   . Fixed crash in Dom\Node::lookupPrefix() on a text node inside a DTD entity
     declaration. (Ian Mattas)
+  . Fixed bug GH-25998 (Dom\Element::setIdAttributeNS() rejects null for
+    $namespace). (Tomasz Kowalczyk)

 - FFI:
   . Fixed bug GH-25558 (struct with an enum field passed by value is described
diff --git a/ext/dom/element.c b/ext/dom/element.c
index f370b0e958d..bba98fba55b 100644
--- a/ext/dom/element.c
+++ b/ext/dom/element.c
@@ -1400,7 +1400,7 @@ PHP_METHOD(DOMElement, setIdAttribute)
 /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNS
 Since: DOM Level 3
 */
-PHP_METHOD(DOMElement, setIdAttributeNS)
+static void dom_element_set_id_attribute_ns(INTERNAL_FUNCTION_PARAMETERS, bool modern)
 {
 	zval *id;
 	xmlNodePtr elemp;
@@ -1411,12 +1411,16 @@ PHP_METHOD(DOMElement, setIdAttributeNS)
 	bool is_id;

 	id = ZEND_THIS;
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssb", &uri, &uri_len, &name, &name_len, &is_id) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), modern ? "s!sb" : "ssb", &uri, &uri_len, &name, &name_len, &is_id) == FAILURE) {
 		RETURN_THROWS();
 	}

 	DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);

+	if (modern && uri_len == 0) {
+		uri = NULL;
+	}
+
 	attrp = xmlHasNsProp(elemp, BAD_CAST name, BAD_CAST uri);
 	if (attrp == NULL || attrp->type == XML_ATTRIBUTE_DECL) {
 		php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
@@ -1424,6 +1428,16 @@ PHP_METHOD(DOMElement, setIdAttributeNS)
 		php_set_attribute_id(attrp, is_id, intern->document);
 	}
 }
+
+PHP_METHOD(DOMElement, setIdAttributeNS)
+{
+	dom_element_set_id_attribute_ns(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
+}
+
+PHP_METHOD(Dom_Element, setIdAttributeNS)
+{
+	dom_element_set_id_attribute_ns(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
+}
 /* }}} end dom_element_set_id_attribute_ns */

 /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNode
diff --git a/ext/dom/php_dom.stub.php b/ext/dom/php_dom.stub.php
index 81713403e0e..a7edb6e9a68 100644
--- a/ext/dom/php_dom.stub.php
+++ b/ext/dom/php_dom.stub.php
@@ -1661,7 +1661,6 @@ public function insertAdjacentText(AdjacentPosition $where, string $data): void

         /** @implementation-alias DOMElement::setIdAttribute */
         public function setIdAttribute(string $qualifiedName, bool $isId): void {}
-        /** @implementation-alias DOMElement::setIdAttributeNS */
         public function setIdAttributeNS(?string $namespace, string $qualifiedName, bool $isId): void {}
         public function setIdAttributeNode(Attr $attr, bool $isId): void {}

diff --git a/ext/dom/php_dom_arginfo.h b/ext/dom/php_dom_arginfo.h
index ea42d6de498..64884f4d08e 100644
Binary files a/ext/dom/php_dom_arginfo.h and b/ext/dom/php_dom_arginfo.h differ
diff --git a/ext/dom/tests/modern/spec/gh25998.phpt b/ext/dom/tests/modern/spec/gh25998.phpt
new file mode 100644
index 00000000000..e15ad766f64
--- /dev/null
+++ b/ext/dom/tests/modern/spec/gh25998.phpt
@@ -0,0 +1,34 @@
+--TEST--
+GH-25998: Dom\Element::setIdAttributeNS() rejects null for $namespace
+--EXTENSIONS--
+dom
+--FILE--
+<?php
+
+$dom = Dom\XMLDocument::createFromString('<root xmlns:p="urn:p"><a key="x"/><b p:key="y"/></root>');
+$a = $dom->documentElement->firstElementChild;
+$b = $a->nextElementSibling;
+
+$a->setIdAttributeNS(null, 'key', true);
+var_dump($dom->getElementById('x') === $a);
+$a->setIdAttributeNS(null, 'key', false);
+var_dump($dom->getElementById('x'));
+$a->setIdAttributeNS('', 'key', true);
+var_dump($dom->getElementById('x') === $a);
+
+$b->setIdAttributeNS('urn:p', 'key', true);
+var_dump($dom->getElementById('y') === $b);
+
+try {
+    $b->setIdAttributeNS(null, 'key', true);
+} catch (DOMException $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+bool(true)
+NULL
+bool(true)
+bool(true)
+Not Found Error