1--TEST--
2registerPHPFunctions() with callables - error cases
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new DOMDocument();
9$doc->loadHTML('<a href="https://php.net">hello</a>');
10
11$xpath = new DOMXPath($doc);
12try {
13    $xpath->registerPhpFunctions("nonexistent");
14} catch (TypeError $e) {
15    echo $e->getMessage(), "\n";
16}
17
18try {
19    $xpath->registerPhpFunctions(function () {});
20} catch (TypeError $e) {
21    echo $e->getMessage(), "\n";
22}
23
24try {
25    $xpath->registerPhpFunctions([function () {}]);
26} catch (Throwable $e) {
27    echo $e->getMessage(), "\n";
28}
29
30try {
31    $xpath->registerPhpFunctions([var_dump(...)]);
32} catch (Throwable $e) {
33    echo $e->getMessage(), "\n";
34}
35
36try {
37    $xpath->registerPhpFunctions(["nonexistent"]);
38} catch (Throwable $e) {
39    echo $e->getMessage(), "\n";
40}
41
42try {
43    $xpath->registerPhpFunctions(["" => var_dump(...)]);
44} catch (Throwable $e) {
45    echo $e->getMessage(), "\n";
46}
47
48try {
49    $xpath->registerPhpFunctions(["\0" => var_dump(...)]);
50} catch (Throwable $e) {
51    echo $e->getMessage(), "\n";
52}
53
54try {
55    $xpath->registerPhpFunctions("");
56} catch (Throwable $e) {
57    echo $e->getMessage(), "\n";
58}
59
60?>
61--EXPECT--
62DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "nonexistent" not found or invalid function name
63DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be of type array|string|null, Closure given
64Object of class Closure could not be converted to string
65Object of class Closure could not be converted to string
66DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with valid callbacks as values, function "nonexistent" not found or invalid function name
67DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
68DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
69DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a valid callback name
70