php-src/ext/xml/tests/set_element_handler_trampoline_errors.phpt
George Peter Banyard 0e5d654409
ext/xml: Refactor extension to use FCC instead of zvals for handlers (#12340)
To get proper errors and sensible behaviour, as the current behaviour is somewhat insane and part of it should be axed ASAP.

The behaviour is mostly intact with some minor BC breaks which are mentioned in UPGRADING.

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-10-20 13:14:55 +01:00

46 lines
1.1 KiB
PHP

--TEST--
Test xml_set_element_handler handlers as trampoline callback
--EXTENSIONS--
xml
--FILE--
<?php
class TrampolineTest {
public function __call(string $name, array $arguments) {
echo 'Trampoline for ', $name, PHP_EOL;
echo 'Tag: ', $arguments[1], PHP_EOL;
}
}
$o = new TrampolineTest();
$startCallback = [$o, 'start_handler'];
$endCallback = [$o, 'end_handler'];
$xml = <<<HERE
<a>
<b/>
<c>Text</c>
</a>
HERE;
$parser = xml_parser_create();
echo "2nd arg is rubbish:\n";
try {
xml_set_element_handler($parser, [], $endCallback);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo "3rd arg is rubbish:\n";
try {
xml_set_element_handler($parser, $startCallback, []);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
xml_parser_free($parser);
?>
--EXPECT--
2nd arg is rubbish:
TypeError: xml_set_element_handler(): Argument #2 ($start_handler) must be of type callable|string|null
3rd arg is rubbish:
TypeError: xml_set_element_handler(): Argument #2 ($start_handler) must be of type callable|string|null