Skip to content

Instantly share code, notes, and snippets.

@blar
Created September 24, 2012 20:19
Show Gist options
  • Select an option

  • Save blar/3778102 to your computer and use it in GitHub Desktop.

Select an option

Save blar/3778102 to your computer and use it in GitHub Desktop.
<?php
class LineIterator {
protected $handle;
public function __construct($file) {
$this->handle = fopen($file, 'r');
}
public function __invoke() {
return fgets($this->handle);
}
}
$iterator = new LineIterator('/etc/hosts');
while($line = $iterator()) {
echo $line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment