Skip to content

Commit 3de22a8

Browse files
committed
ext/spl: Add trampoline test for iterator_apply()
1 parent e547fe4 commit 3de22a8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
SPL: iterator_apply() with a trampoline
3+
--FILE--
4+
<?php
5+
6+
class TrampolineTest {
7+
public function __call(string $name, array $arguments) {
8+
echo 'Trampoline for ', $name, PHP_EOL;
9+
var_dump($arguments);
10+
if ($name === 'trampolineThrow') {
11+
throw new Exception('boo');
12+
}
13+
}
14+
}
15+
$o = new TrampolineTest();
16+
$callback = [$o, 'trampoline'];
17+
$callbackThrow = [$o, 'trampolineThrow'];
18+
19+
$it = new RecursiveArrayIterator([1, 21, 22]);
20+
21+
try {
22+
$iterations = iterator_apply($it, $callback);
23+
var_dump($iterations);
24+
} catch (Throwable $e) {
25+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
26+
}
27+
try {
28+
iterator_apply($it, $callbackThrow);
29+
} catch (Throwable $e) {
30+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
31+
}
32+
try {
33+
iterator_apply($it, $callback, 'not an array');
34+
} catch (Throwable $e) {
35+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
36+
}
37+
38+
?>
39+
--EXPECT--
40+
Trampoline for trampoline
41+
array(0) {
42+
}
43+
int(1)
44+
Trampoline for trampolineThrow
45+
array(0) {
46+
}
47+
Exception: boo
48+
TypeError: iterator_apply(): Argument #3 ($args) must be of type ?array, string given

0 commit comments

Comments
 (0)