Em Tue, 24 Jul 2012 19:56:46 +0200, Alex Aulbach <alex.aulb...@gmail.com> escreveu:

2012/7/24 Andrew Faulds <a...@ajf.me>:
Much easier to make an iterator with a function than as a class.

2012/7/24 Yahav Gindi Bar <g.b.ya...@gmail.com>:
I agree, implementing a class only for iterator may be pain sometimes, and functions is much better - especially when 5.3 got the anonymous functions, so we can even use the generators for iterator functions in class methods which can be great.

Ok, why not call it "iterator" or "generator" or "huffpuff" instead of
"function"? It's just the naming, which disturbs me, because a
function is something which is, when called once finished once. I
don't like mathematics, but that is one of the definition of a
function:

http://en.wikipedia.org/wiki/Function_%28mathematics%29
"each input is related to exactly one output"


Other have already explained that PHP functions are not strictly mathematical functions, but generators nevertheless somewhat fit that description. When you have function foo() { ... yield /* ... */; ... } and you call foo(), you get the same thing every time: a Generator object. It so happens that the implementation of that object is inside the body of the function.

Maybe this helps you reason about the feature.

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to