Skip to content

Commit 6baf3a7

Browse files
committed
Fix UNKNOWN default values in ext/xsl
1 parent c5686d8 commit 6baf3a7

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

ext/xsl/php_xsl.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public function removeParameter(string $namespace, string $name) {}
4141
public function hasExsltSupport() {}
4242

4343
/**
44-
* @param string|array $restrict
44+
* @param string|array|null $restrict
4545
* @return void
4646
*/
47-
public function registerPHPFunctions($restrict = UNKNOWN) {}
47+
public function registerPHPFunctions($restrict = null) {}
4848

4949
/** @return bool */
5050
public function setProfiling(?string $filename) {}

ext/xsl/php_xsl_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_hasExsltSupport, 0, 0, 0)
3535
ZEND_END_ARG_INFO()
3636

3737
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_registerPHPFunctions, 0, 0, 0)
38-
ZEND_ARG_INFO(0, restrict)
38+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, restrict, "null")
3939
ZEND_END_ARG_INFO()
4040

4141
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_setProfiling, 0, 0, 1)

ext/xsl/xsltprocessor.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -760,33 +760,46 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions)
760760
{
761761
zval *id = ZEND_THIS;
762762
xsl_object *intern;
763-
zval *array_value, *entry, new_string;
764-
zend_string *name;
763+
zval *zv = NULL, *entry, new_string;
764+
765+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zv) == FAILURE) {
766+
RETURN_THROWS();
767+
}
765768

766-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &array_value) == SUCCESS) {
769+
if (!zv) {
767770
intern = Z_XSL_P(id);
771+
intern->registerPhpFunctions = 1;
768772

769-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) {
770-
zend_string *str = zval_try_get_string(entry);
771-
if (UNEXPECTED(!str)) {
772-
return;
773-
}
774-
ZVAL_LONG(&new_string, 1);
775-
zend_hash_update(intern->registered_phpfunctions, str, &new_string);
776-
zend_string_release(str);
777-
} ZEND_HASH_FOREACH_END();
773+
return;
774+
}
778775

779-
intern->registerPhpFunctions = 2;
780-
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S", &name) == SUCCESS) {
781-
intern = Z_XSL_P(id);
776+
switch (Z_TYPE_P(zv)) {
777+
case IS_ARRAY:
778+
intern = Z_XSL_P(id);
782779

783-
ZVAL_LONG(&new_string,1);
784-
zend_hash_update(intern->registered_phpfunctions, name, &new_string);
785-
intern->registerPhpFunctions = 2;
780+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zv), entry) {
781+
zend_string *str = zval_try_get_string(entry);
782+
if (UNEXPECTED(!str)) {
783+
return;
784+
}
785+
ZVAL_LONG(&new_string, 1);
786+
zend_hash_update(intern->registered_phpfunctions, str, &new_string);
787+
zend_string_release(str);
788+
} ZEND_HASH_FOREACH_END();
786789

787-
} else if (zend_parse_parameters_none() == SUCCESS) {
788-
intern = Z_XSL_P(id);
789-
intern->registerPhpFunctions = 1;
790+
intern->registerPhpFunctions = 2;
791+
break;
792+
793+
case IS_STRING:
794+
intern = Z_XSL_P(id);
795+
796+
ZVAL_LONG(&new_string, 1);
797+
zend_hash_update(intern->registered_phpfunctions, Z_STR_P(zv), &new_string);
798+
intern->registerPhpFunctions = 2;
799+
break;
800+
801+
default:
802+
zend_argument_type_error(1, "must be of type string|array|null, %s given", zend_zval_type_name(zv));
790803
}
791804
}
792805
/* }}} end XSLTProcessor::registerPHPFunctions(); */

0 commit comments

Comments
 (0)