1--TEST-- 2Test interaction of Generator::getReturn() and finally 3--FILE-- 4<?php 5 6function gen1() { 7 try { 8 throw new Exception("gen1() throw"); 9 } finally { 10 return 42; 11 } 12 yield; 13} 14 15// The exception was discarded, so this works 16$gen = gen1(); 17var_dump($gen->getReturn()); 18 19function gen2() { 20 try { 21 return 42; 22 } finally { 23 throw new Exception("gen2() throw"); 24 } 25 yield; 26} 27 28$gen = gen2(); 29try { 30 // This will throw an exception (from the finally) 31 // during auto-priming, so fails 32 var_dump($gen->getReturn()); 33} catch (Exception $e) { 34 echo $e->getMessage(), "\n"; 35} 36try { 37 // This fails, because the return value was discarded 38 var_dump($gen->getReturn()); 39} catch (Exception $e) { 40 echo $e->getMessage(), "\n"; 41} 42 43?> 44--EXPECT-- 45int(42) 46gen2() throw 47Cannot get return value of a generator that hasn't returned 48