Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream's eof() function does not return correct result. #129

Closed
katmsft opened this issue Jan 5, 2017 · 2 comments
Closed

Stream's eof() function does not return correct result. #129

katmsft opened this issue Jan 5, 2017 · 2 comments

Comments

@katmsft
Copy link

katmsft commented Jan 5, 2017

Hi, recently during development I found that the eof() method of StreamInterface does not work properly. I do not know if it is me who misunderstood the behavior or there is a bug regarding this issue. The code of me testing the case is like this.

$resource = fread('test.txt');//Any test txt file. Better not too large.
$content = Psr7\stream_for($resource);
$size = $content->getSize();
$content->read($size);//Read exactly the size of the file.
$isEof = $content->eof() == true? 'is end of file' : 'not end of file';
echo "{$size}\n{$isEof}\n";//Print the size of the file. Result also show 'not end of file';

If I get the remaining contents of the file using getContents or read($length) afterwards it returns an empty string, and then can have eof() returning the correct result.

@Tobion
Copy link
Member

Tobion commented Feb 20, 2017

This is a known behavior of feof that psr7 is just wrapping around so it inherits the same thing. See comments in http://php.net/manual/en/function.feof.php

@jackbentley
Copy link

Note that the PSR interface defines eof() as...

Returns true if the stream is at the end of the stream.

However, the current implementation (and that of feof()) is more akin to...

Returns true if the stream is after the end of the stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants