diff --git a/language/predefined/generator/send.xml b/language/predefined/generator/send.xml index f100e836f4..5f3d03c1a5 100644 --- a/language/predefined/generator/send.xml +++ b/language/predefined/generator/send.xml @@ -14,15 +14,14 @@ mixedvalue - Sends the given value to the generator as the result of the yield expression - and resumes execution of the generator. + Sends the given value to the generator as the result of the current &yield; + expression and resumes execution of the generator. - - Generator::send allows values to be injected into - generator functions while iterating over them. The injected value will be - returned from the &yield; statement and can then be used like any other - variable within the generator function. + If the generator is not at a &yield; expression when this method is called, it + will first be let to advance to the first &yield; expression before sending the + value. As such it is not necessary to "prime" PHP generators with a + Generator::next call (like it is done in Python). @@ -33,7 +32,8 @@ value - + Value to send into the generator. This value will be the return value of the + &yield; expression the generator is currently at. @@ -57,6 +57,7 @@ function printer() { $printer = printer(); $printer->send('Hello world!'); +$printer->send('Bye world!'); ?> ]]> @@ -64,6 +65,7 @@ $printer->send('Hello world!'); diff --git a/language/predefined/generator/throw.xml b/language/predefined/generator/throw.xml index 5edb565125..ad438d6e41 100644 --- a/language/predefined/generator/throw.xml +++ b/language/predefined/generator/throw.xml @@ -10,9 +10,18 @@ &reftitle.description; - public voidGenerator::throw + public mixedGenerator::throw Exceptionexception + + Throws an exception into the generator and resumes execution of the generator. + The behavior will be the same as if the current &yield; expression was replaced with + a throw $exception statement. + + + If the generator is already closed when this method is invoked, the exception will + be thrown in the caller's context instead. + @@ -22,12 +31,49 @@ exception - + Exception to throw into the generator. + + + &reftitle.examples; + + + Throwing an exception into a generator + +getMessage()}\n"; + } + echo "Bar\n"; +} + +$gen = gen(); +$gen->rewind(); +$gen->throw(new Exception('Test')); +?> +]]> + + &example.outputs; + + + + + + + &reftitle.returnvalues;