From the PHP rfc:generators
The return value of the
yield
expression is whatever was sent to the generator usingsend()
. If nothing was sent (e.g. duringforeach
iteration)null
is returned.
Your foreach
code never send()
s anything into the generator, so yield
always returns null
.