Recall & Review
beginner
What is a generator in PHP?
A generator is a special function that can pause its execution and yield values one at a time, allowing you to iterate over data without creating an entire array in memory.
Click to reveal answer
intermediate
How do you get the return value of a generator in PHP?
You get the return value of a generator by calling the
getReturn() method on the generator object after it has finished running.Click to reveal answer
beginner
What keyword is used inside a generator to specify its return value?
The
return keyword is used inside a generator to specify a final return value that can be retrieved after iteration ends.Click to reveal answer
intermediate
What happens if you try to get the return value of a generator before it finishes?
If you try to get the return value before the generator finishes, it will throw an exception because the return value is only available after the generator has completed.
Click to reveal answer
intermediate
Why are generator return values useful?
Generator return values let you send a final result or summary after all yielded values are processed, which is helpful for things like totals or status messages.Click to reveal answer
Which method retrieves the return value of a finished generator in PHP?
✗ Incorrect
The correct method is
getReturn() to get the return value after the generator finishes.What keyword inside a generator function sets the return value?
✗ Incorrect
The
return keyword sets the final return value of the generator.What happens if you call
getReturn() on a generator that is still running?✗ Incorrect
Calling
getReturn() before the generator finishes throws an exception.Which of these is NOT true about generator return values?
✗ Incorrect
Return values do not replace yielded values; they are separate and available only after iteration.
Why might you use a generator return value?
✗ Incorrect
Return values let you send a final summary or result after all values have been yielded.
Explain how to retrieve the return value from a PHP generator and why it might be useful.
Think about what happens after you finish looping through all yielded values.
You got /4 concepts.
Describe the difference between yielding values and returning a value in a PHP generator.
One is for producing data step-by-step, the other is for a final message.
You got /4 concepts.