News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Generators in PHP
August 06, 2013 @ 12:25:50

On PHPMaster.com a tutorial has been posted talking about one of the newer features in PHP - generators. In the tutorial Stefan Froelich walks you through how they work and a few examples of their use.

Generators in PHP If you've followed my previous posts about iterators then you'll know that iteration is an important programming concept, but implementing the required interfaces to create an iterable object can be a hassle at best because of the amount of boilerplate code that is required. With the release of PHP 5.5, we finally have generators!

He starts with a more practical example - pulling lines from a file, one at a time, without the overhead of having to read in the entire file at once. He also includes an example of returning the keys from the generator (not just the value) and injecting values with the "send" method.

0 comments voice your opinion now!
generator tutorial introduction example yield inject keys

Link: http://phpmaster.com/generators-in-php

blog comments powered by Disqus

Similar Posts

Anthony Ferrara: Programming With Anthony - Dependency Injection

SitePoint PHP Blog: Responsive Images Using Picturefill and PHP

Noupe.com: 20 Useful PHP + jQuery Components & Tuts for Everyday Project

Jakub Zalas' Blog: Mocking Symfony Container services in Behat scenarios with Mockery

Content with Style: Custom Zend Form Image Upload Element


Community Events





Don't see your event here?
Let us know!


laravel zendserver language framework development introduction interview threedevsandamaybe code release podcast deployment symfony api conference bugfix tips series community list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework