mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
ext/spl: Add trampoline test for iterator_apply()
This commit is contained in:
parent
e547fe40df
commit
3de22a84e8
1 changed files with 48 additions and 0 deletions
48
ext/spl/tests/spl_iterator_apply_with_trampoline.phpt
Normal file
48
ext/spl/tests/spl_iterator_apply_with_trampoline.phpt
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue