Yesterday, I've learned that PHP has a yield()
method. I was unure about its usefulness in PHP.
A colleague said it could help for SQL statements returning many rows causing potential memory issues. I believe he was refering to fetchAll()
.
But, instead of using fetchAll()
, one can also use fetch()
and process rows one-by-one. So, yield()
is not key to solving the issue he is referring to.
Am I missing something about yield()
vs fetch()
here? Are there more benefits to using yield()
and generators?
P.S.: It's true that it's easier to write clean, readable and maitainable code in large applications with yield()
than with with fetch()
.