Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jhoff's avatar
Level 14

PHP Generator syntax ( yield )

http://php.net/manual/en/language.generators.syntax.php

This seems like it could be a useful feature, but I have yet to see it in action.

Does anyone here actually use generator functions?

0 likes
1 reply
MarkLL's avatar

I have used it with Amazon S3 file uploads. It basically returns a Promise/A+ object to enable asynchronous workflows. More info here: https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/promises.html

You can also use it to process a large list without having to actually load the entire "list" before processing. (eg have a for loop that calls the generator function to process a line read in from a large file that would normally exhaust free memory.)

I will admit it took a while for the concepts and usage/execution to sink in.

Please or to participate in this conversation.