PHP 5.5 was recently released, introducing several exciting new features to the language. In this article, we’ll go through some of the most interesting additions and discuss the benefits they provide to developers.
Generators are one of the most eagerly anticipated new features. They provide a way to handle iteration without having to write a class that implements the
Iterator interface. Making a class conform to the Iterator interface requires a substantial amount of boilerplate code, so being able to avoid this by using generators can significantly reduce the size and complexity of code that developers must write.
Generators derive their functionality from the new
yield keyword. A generator looks very similar to a normal function, but instead of returning a single value, a generator may yield any number of values.
To properly illustrate the power of generators, an example is needed. Consider PHP’s
range() function, which returns an…
Ver la entrada original 1.236 palabras más