From: Nikita Popov Date: Fri, 17 Jul 2020 14:10:49 +0000 (+0200) Subject: Use string|array type in DOMXPath::registerPhpFunctions() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d449d1dbbf7cefb3d249a629c5c61f6b16015583;p=php Use string|array type in DOMXPath::registerPhpFunctions() --- diff --git a/ext/dom/php_dom.stub.php b/ext/dom/php_dom.stub.php index 5b553b8035..f84282542d 100644 --- a/ext/dom/php_dom.stub.php +++ b/ext/dom/php_dom.stub.php @@ -425,11 +425,8 @@ class DOMXPath /** @return bool */ public function registerNamespace(string $prefix, string $namespaceURI) {} - /** - * @param string|array $restrict - * @return bool|null - */ - public function registerPhpFunctions($restrict = null) {} + /** @return bool|null */ + public function registerPhpFunctions(string|array|null $restrict = null) {} } #endif diff --git a/ext/dom/php_dom_arginfo.h b/ext/dom/php_dom_arginfo.h index de2ea0d73a..5724b98b79 100644 --- a/ext/dom/php_dom_arginfo.h +++ b/ext/dom/php_dom_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ce4644d8cb6fdf0f3b9f5d1cbac773b406884ad9 */ + * Stub hash: a9c30985948768261ea275fdbde598cf9119029e */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1) ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0) @@ -441,7 +441,7 @@ ZEND_END_ARG_INFO() #if defined(LIBXML_XPATH_ENABLED) ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMXPath_registerPhpFunctions, 0, 0, 0) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, restrict, "null") + ZEND_ARG_TYPE_MASK(0, restrict, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() #endif diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index b3181972ca..e45ca84d8c 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -492,29 +492,30 @@ PHP_METHOD(DOMXPath, evaluate) PHP_METHOD(DOMXPath, registerPhpFunctions) { zval *id = ZEND_THIS; - dom_xpath_object *intern; - zval *array_value, *entry, new_string; - zend_string *name; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &array_value) == SUCCESS) { - intern = Z_XPATHOBJ_P(id); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) { + dom_xpath_object *intern = Z_XPATHOBJ_P(id); + zval *entry, new_string; + zend_string *name = NULL; + HashTable *ht = NULL; + + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(name, ht) + ZEND_PARSE_PARAMETERS_END(); + + if (ht) { + ZEND_HASH_FOREACH_VAL(ht, entry) { zend_string *str = zval_get_string(entry); - ZVAL_LONG(&new_string,1); + ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_string_release_ex(str, 0); } ZEND_HASH_FOREACH_END(); intern->registerPhpFunctions = 2; RETURN_TRUE; - - } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S", &name) == SUCCESS) { - intern = Z_XPATHOBJ_P(id); - + } else if (name) { ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, name, &new_string); intern->registerPhpFunctions = 2; } else { - intern = Z_XPATHOBJ_P(id); intern->registerPhpFunctions = 1; }