ext/spl: Add trampoline test for iterator_apply()

This commit is contained in:
Gina Peter Banyard 2025-01-05 01:10:21 +00:00
parent e547fe40df
commit 3de22a84e8

View file

@ -0,0 +1,48 @@
--TEST--
SPL: iterator_apply() with a trampoline
--FILE--
<?php
class TrampolineTest {
public function __call(string $name, array $arguments) {
echo 'Trampoline for ', $name, PHP_EOL;
var_dump($arguments);
if ($name === 'trampolineThrow') {
throw new Exception('boo');
}
}
}
$o = new TrampolineTest();
$callback = [$o, 'trampoline'];
$callbackThrow = [$o, 'trampolineThrow'];
$it = new RecursiveArrayIterator([1, 21, 22]);
try {
$iterations = iterator_apply($it, $callback);
var_dump($iterations);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
iterator_apply($it, $callbackThrow);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
iterator_apply($it, $callback, 'not an array');
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
Trampoline for trampoline
array(0) {
}
int(1)
Trampoline for trampolineThrow
array(0) {
}
Exception: boo
TypeError: iterator_apply(): Argument #3 ($args) must be of type ?array, string given