Skip to content

Commit

Permalink
Use string|array type in DOMXPath::registerPhpFunctions()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 17, 2020
1 parent f9ced0d commit d449d1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
7 changes: 2 additions & 5 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,8 @@ public function query(string $expr, ?DOMNode $context = null, bool $registerNode
/** @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

Expand Down
4 changes: 2 additions & 2 deletions ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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

Expand Down
27 changes: 14 additions & 13 deletions ext/dom/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d449d1d

Please sign in to comment.