Use string|array type in DOMXPath::registerPhpFunctions()

This commit is contained in:
Nikita Popov 2020-07-17 16:10:49 +02:00
parent f9ced0d4f7
commit d449d1dbbf
3 changed files with 17 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
dom_xpath_object *intern = Z_XPATHOBJ_P(id);
zval *entry, new_string;
zend_string *name = NULL;
HashTable *ht = NULL;
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) {
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;
}