|
| 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