feof
-
The
feoffunction tests if a file pointer has reached end of file (EOF).This example demonstrates by making a dummy read, which places the pointer at the end of the file. The result of
feofis thentrue.PHP
$f = fopen('/path/to/foobar', 'r'); fread($f); var_export( feof($f) ); //=> true fclose($f);
In Ruby, the
File#eofinstance method works the same way.Ruby
File.open('/path/to/foobar', 'r') do |f| f.read p f.eof #=> true end
The
File#eofinstance method is also aliased asFile#eof?. It’s a common Ruby idiom for methods that return boolean be written like this, as if asking a question.Both
File#eofandFile#eof?are commonly used, so choose the one that is most expressive for your usage.
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

