Skip to content

Commit aa754ba

Browse files
committed
FR #79344: xmlwriter_write_attribute_ns: $prefix should be nullable
The `$prefix` parameter of `xmlwriter_write_element_ns()` and `xmlwriter_start_element_ns()` is nullable, what allows these functions to be used instead of their non NS variants. Consequently, we make the `$prefix` parameter of `xmlwriter_write_attribute_ns()` and `xmlwriter_start_attribute_ns()` nullable as well.
1 parent 2c207eb commit aa754ba

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ PHP NEWS
190190
- XMLWriter:
191191
. Changed functions to accept/return XMLWriter objects instead of resources.
192192
(cmb)
193+
. Implemented FR #79344 (xmlwriter_write_attribute_ns: $prefix should be
194+
nullable). (cmb)
193195

194196
- Zip:
195197
. Fixed bug #72374 (remove_path strips first char of filename). (tyage, Remi)

ext/xmlwriter/php_xmlwriter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ PHP_FUNCTION(xmlwriter_start_attribute_ns)
307307
int retval;
308308
zval *self;
309309

310-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!", &self, xmlwriter_class_entry_ce,
310+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!ss!", &self, xmlwriter_class_entry_ce,
311311
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
312312
RETURN_THROWS();
313313
}
@@ -365,7 +365,7 @@ PHP_FUNCTION(xmlwriter_write_attribute_ns)
365365
int retval;
366366
zval *self;
367367

368-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!s", &self, xmlwriter_class_entry_ce,
368+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!ss!s", &self, xmlwriter_class_entry_ce,
369369
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
370370
RETURN_THROWS();
371371
}

ext/xmlwriter/php_xmlwriter.stub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function xmlwriter_end_attribute(XMLWriter $xmlwriter): bool {}
2020

2121
function xmlwriter_write_attribute(XMLWriter $xmlwriter, string $name, string $value): bool {}
2222

23-
function xmlwriter_start_attribute_ns(XMLWriter $xmlwriter, string $prefix, string $name, ?string $uri): bool {}
23+
function xmlwriter_start_attribute_ns(XMLWriter $xmlwriter, ?string $prefix, string $name, ?string $uri): bool {}
2424

25-
function xmlwriter_write_attribute_ns(XMLWriter $xmlwriter, string $prefix, string $name, ?string $uri, string $content): bool {}
25+
function xmlwriter_write_attribute_ns(XMLWriter $xmlwriter, ?string $prefix, string $name, ?string $uri, string $content): bool {}
2626

2727
function xmlwriter_start_element(XMLWriter $xmlwriter, string $name): bool {}
2828

@@ -116,10 +116,10 @@ public function endAttribute(): bool {}
116116
public function writeAttribute(string $name, string $value): bool {}
117117

118118
/** @alias xmlwriter_start_attribute_ns */
119-
public function startAttributeNs(string $prefix, string $name, ?string $uri): bool {}
119+
public function startAttributeNs(?string $prefix, string $name, ?string $uri): bool {}
120120

121121
/** @alias xmlwriter_write_attribute_ns */
122-
public function writeAttributeNs(string $prefix, string $name, ?string $uri, string $content): bool {}
122+
public function writeAttributeNs(?string $prefix, string $name, ?string $uri, string $content): bool {}
123123

124124
/** @alias xmlwriter_start_element */
125125
public function startElement(string $name): bool {}

ext/xmlwriter/php_xmlwriter_arginfo.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ ZEND_END_ARG_INFO()
3838

3939
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 4, _IS_BOOL, 0)
4040
ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
41-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
41+
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
4242
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
4343
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
4444
ZEND_END_ARG_INFO()
4545

4646
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 5, _IS_BOOL, 0)
4747
ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
48-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
48+
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
4949
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
5050
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
5151
ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0)
@@ -57,12 +57,7 @@ ZEND_END_ARG_INFO()
5757

5858
#define arginfo_xmlwriter_full_end_element arginfo_xmlwriter_start_comment
5959

60-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_element_ns, 0, 4, _IS_BOOL, 0)
61-
ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
62-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
63-
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
64-
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
65-
ZEND_END_ARG_INFO()
60+
#define arginfo_xmlwriter_start_element_ns arginfo_xmlwriter_start_attribute_ns
6661

6762
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_element, 0, 2, _IS_BOOL, 0)
6863
ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
@@ -210,13 +205,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttribute,
210205
ZEND_END_ARG_INFO()
211206

212207
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startAttributeNs, 0, 3, _IS_BOOL, 0)
213-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
208+
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
214209
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
215210
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
216211
ZEND_END_ARG_INFO()
217212

218213
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttributeNs, 0, 4, _IS_BOOL, 0)
219-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
214+
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
220215
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
221216
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
222217
ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0)
@@ -228,11 +223,7 @@ ZEND_END_ARG_INFO()
228223

229224
#define arginfo_class_XMLWriter_fullEndElement arginfo_class_XMLWriter_openMemory
230225

231-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startElementNs, 0, 3, _IS_BOOL, 0)
232-
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
233-
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
234-
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
235-
ZEND_END_ARG_INFO()
226+
#define arginfo_class_XMLWriter_startElementNs arginfo_class_XMLWriter_startAttributeNs
236227

237228
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeElement, 0, 1, _IS_BOOL, 0)
238229
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)

ext/xmlwriter/tests/bug79344.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
FR #79344 (xmlwriter_write_attribute_ns: $prefix should be nullable)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('xmlwriter')) die('skip xmlwriter extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$writer = new XMLWriter;
10+
$writer->openMemory();
11+
$writer->setIndent(true);
12+
$writer->startElement('foo');
13+
14+
$writer->writeAttributeNS(null, 'test1', null, 'test1');
15+
$writer->startAttributeNS(null, 'test2', null);
16+
$writer->text('test2');
17+
$writer->endAttribute();
18+
19+
$writer->endElement();
20+
echo $writer->outputMemory();
21+
?>
22+
--EXPECT--
23+
<foo test1="test1" test2="test2"/>

0 commit comments

Comments
 (0)