Skip to content

Internal stream casting should not emit lost bytes warning twice #10092

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

Closed
Girgias opened this issue Dec 13, 2022 · 5 comments
Closed

Internal stream casting should not emit lost bytes warning twice #10092

Girgias opened this issue Dec 13, 2022 · 5 comments

Comments

@Girgias
Copy link
Member

Girgias commented Dec 13, 2022

Description

The following code:

<?php
$handle = fopen('http://example.com', 'r');
var_dump(stream_isatty($handle));

Resulted in this output:


Warning: stream_isatty(): 1256 bytes of buffered data lost during stream conversion! in test.php on line 3

Warning: stream_isatty(): 1256 bytes of buffered data lost during stream conversion! in test.php on line 3
bool(false)

But I expected this output instead:


Warning: stream_isatty(): 1256 bytes of buffered data lost during stream conversion! in test.php on line 3
bool(false)

Or ideally:

bool(false)

The thing is that if one reads the original stream via:

$contents = '';
while (!feof($handle)) {
    $contents .= fread($handle, 8192);
}
var_dump($contents);

One does get the totality of the 1256 bytes of output.
So I'm confused as to why the warning is emitted in the first place.

PHP Version

master

Operating System

No response

@Girgias
Copy link
Member Author

Girgias commented Dec 13, 2022

Okay, I have figured why the warning is emitted twice. This warning is not gated by a if (show_err) { clause.

Girgias added a commit to Girgias/php-src that referenced this issue Dec 13, 2022
…arning twice)

The reason why the warning was emitted is because it was not guarded via the show_err parameter.

This parameter is set to false/0 via the macro function php_stream_can_cast() to check this silently.

The warning is completely removed as this function in particuliar sets this
parameter to 0 when it casts the streamas it "performs a cast" just to retrieve
the underlying file number.
@danepowell
Copy link

I'm a little lost trying to follow the conversation in #10093 and #10173. As an end user of functions like stream_isatty and posix_isatty, I feel like they should never emit such a warning. Who cares what data is lost in conversion as long as the function returns the correct result? How am I supposed to respond to such a warning?

I think either the warning should be suppressed, or guidance should be provided on how to resolve it.

@Girgias
Copy link
Member Author

Girgias commented Apr 29, 2023

#10173 would fix the warning being displayed, because it indeed makes no sense to display it.

@Girgias
Copy link
Member Author

Girgias commented Sep 8, 2023

Fixed via #10173 and the follow-up commits

@danepowell
Copy link

I opened a PR to backport this fix to PHP 8.2 but it hasn't gotten any traction, is there some other process to backport this fix? #13821

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

Successfully merging a pull request may close this issue.

2 participants