1--TEST--
2Error conditions when setting invalid handler callables
3--EXTENSIONS--
4xml
5--FILE--
6<?php
7declare(strict_types=1);
8
9/* Use xml_set_processing_instruction_handler() for generic implementation */
10echo 'Invalid $parser:', PHP_EOL;
11$obj = new stdClass();
12try {
13    xml_set_processing_instruction_handler($obj, null);
14} catch (\Throwable $e) {
15    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
16}
17
18/* Create valid parser */
19$parser = xml_parser_create();
20
21echo 'Invalid callable type true:', PHP_EOL;
22try {
23    xml_set_processing_instruction_handler($parser, true);
24} catch (\Throwable $e) {
25    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
26}
27
28echo 'Invalid callable type int:', PHP_EOL;
29try {
30    xml_set_processing_instruction_handler($parser, 10);
31} catch (\Throwable $e) {
32    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
33}
34
35echo 'String not callable and no object set:', PHP_EOL;
36try {
37    xml_set_processing_instruction_handler($parser, "nonexistent_method");
38} catch (\Throwable $e) {
39    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
40}
41
42echo 'String non existent method on set object:', PHP_EOL;
43xml_set_object($parser, $obj);
44try {
45    xml_set_processing_instruction_handler($parser, "nonexistent_method");
46} catch (\Throwable $e) {
47    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
48}
49
50?>
51--EXPECTF--
52Invalid $parser:
53TypeError: xml_set_processing_instruction_handler(): Argument #1 ($parser) must be of type XMLParser, stdClass given
54Invalid callable type true:
55TypeError: xml_set_processing_instruction_handler(): Argument #2 ($handler) must be of type callable|string|null
56Invalid callable type int:
57TypeError: xml_set_processing_instruction_handler(): Argument #2 ($handler) must be of type callable|string|null
58String not callable and no object set:
59
60Deprecated: xml_set_processing_instruction_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
61ValueError: xml_set_processing_instruction_handler(): Argument #2 ($handler) an object must be set via xml_set_object() to be able to lookup method
62String non existent method on set object:
63
64Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d
65
66Deprecated: xml_set_processing_instruction_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d
67ValueError: xml_set_processing_instruction_handler(): Argument #2 ($handler) method stdClass::nonexistent_method() does not exist
68