1--TEST-- 2SPL: iterator_apply() with a trampoline 3--FILE-- 4<?php 5 6class 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 21try { 22 $iterations = iterator_apply($it, $callback); 23 var_dump($iterations); 24} catch (Throwable $e) { 25 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 26} 27try { 28 iterator_apply($it, $callbackThrow); 29} catch (Throwable $e) { 30 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 31} 32try { 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-- 40Trampoline for trampoline 41array(0) { 42} 43int(1) 44Trampoline for trampolineThrow 45array(0) { 46} 47Exception: boo 48TypeError: iterator_apply(): Argument #3 ($args) must be of type ?array, string given 49