Skip to content

Commit d449d1d

Browse files
committed
Use string|array type in DOMXPath::registerPhpFunctions()
1 parent f9ced0d commit d449d1d

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

ext/dom/php_dom.stub.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,8 @@ public function query(string $expr, ?DOMNode $context = null, bool $registerNode
425425
/** @return bool */
426426
public function registerNamespace(string $prefix, string $namespaceURI) {}
427427

428-
/**
429-
* @param string|array $restrict
430-
* @return bool|null
431-
*/
432-
public function registerPhpFunctions($restrict = null) {}
428+
/** @return bool|null */
429+
public function registerPhpFunctions(string|array|null $restrict = null) {}
433430
}
434431
#endif
435432

ext/dom/php_dom_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: ce4644d8cb6fdf0f3b9f5d1cbac773b406884ad9 */
2+
* Stub hash: a9c30985948768261ea275fdbde598cf9119029e */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@@ -441,7 +441,7 @@ ZEND_END_ARG_INFO()
441441

442442
#if defined(LIBXML_XPATH_ENABLED)
443443
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMXPath_registerPhpFunctions, 0, 0, 0)
444-
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, restrict, "null")
444+
ZEND_ARG_TYPE_MASK(0, restrict, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_NULL, "null")
445445
ZEND_END_ARG_INFO()
446446
#endif
447447

ext/dom/xpath.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -492,29 +492,30 @@ PHP_METHOD(DOMXPath, evaluate)
492492
PHP_METHOD(DOMXPath, registerPhpFunctions)
493493
{
494494
zval *id = ZEND_THIS;
495-
dom_xpath_object *intern;
496-
zval *array_value, *entry, new_string;
497-
zend_string *name;
498-
499-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &array_value) == SUCCESS) {
500-
intern = Z_XPATHOBJ_P(id);
501-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) {
495+
dom_xpath_object *intern = Z_XPATHOBJ_P(id);
496+
zval *entry, new_string;
497+
zend_string *name = NULL;
498+
HashTable *ht = NULL;
499+
500+
ZEND_PARSE_PARAMETERS_START(0, 1)
501+
Z_PARAM_OPTIONAL
502+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(name, ht)
503+
ZEND_PARSE_PARAMETERS_END();
504+
505+
if (ht) {
506+
ZEND_HASH_FOREACH_VAL(ht, entry) {
502507
zend_string *str = zval_get_string(entry);
503-
ZVAL_LONG(&new_string,1);
508+
ZVAL_LONG(&new_string, 1);
504509
zend_hash_update(intern->registered_phpfunctions, str, &new_string);
505510
zend_string_release_ex(str, 0);
506511
} ZEND_HASH_FOREACH_END();
507512
intern->registerPhpFunctions = 2;
508513
RETURN_TRUE;
509-
510-
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S", &name) == SUCCESS) {
511-
intern = Z_XPATHOBJ_P(id);
512-
514+
} else if (name) {
513515
ZVAL_LONG(&new_string, 1);
514516
zend_hash_update(intern->registered_phpfunctions, name, &new_string);
515517
intern->registerPhpFunctions = 2;
516518
} else {
517-
intern = Z_XPATHOBJ_P(id);
518519
intern->registerPhpFunctions = 1;
519520
}
520521

0 commit comments

Comments
 (0)