Re: Re: Generators in PHP
| From: | Rasmus Lerdorf | Date: | Sat, 28 Jul 2012 07:09:46 +0000 |
| Subject: | Re: Re: Generators in PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61854@lists.php.net to get a copy of this message | ||
On 07/27/2012 11:59 PM, Lester Caine wrote:
> Rasmus Lerdorf wrote:
>> I don't think this generator question is any different. We need to
>> explain generators in the simplest way possible. The simplest way to
>> explain generators is to not even worry about them being generators at
>> all. Simply say that functions can now return arrays one element at a
>> time using the new yield keyword. That's all.
>
> It's this 'concept' that I am having trouble seeing in the general
> process that is required using PHP to generate web pages. At the end of
> the day I have to generate the finished page or sub-page so I need all
> the results anyway.
Sure, but that doesn't mean it has to all be in memory at the same time.
You can read lines from a large file line-by-line, process that line and
output the result before you move onto the next line.
-Rasmus