Bug #81475 [Ver->Csd]: stream_isatty emits warning with attached stream wrapper
| From: | git@php.net | Date: | Wed, 29 Sep 2021 11:50:30 +0000 |
| Subject: | Bug #81475 [Ver->Csd]: stream_isatty emits warning with attached stream wrapper | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236916@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81475&edit=1
ID: 81475
Updated by: git@php.net
Reported by: neclimdul at gmail dot com
Summary: stream_isatty emits warning with attached stream
wrapper
-Status: Verified
+Status: Closed
Type: Bug
Package: Streams related
Operating System: any
PHP Version: 8.1.0RC2
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/23e13e2c8f1aa711d8129831c0e1f089cd2e85d1
Log: Fix #81475: stream_isatty emits warning with attached stream wrapper
Previous Comments:
------------------------------------------------------------------------
[2021-09-24 15:42:22] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #81475: stream_isatty emits warning with attached stream wrapper
On GitHub: https://github.com/php/php-src/pull/7513
Patch: https://github.com/php/php-src/pull/7513.patch
------------------------------------------------------------------------
[2021-09-24 14:38:57] neclimdul at gmail dot com
Description:
------------
When testing a stream with stream_isatty, if there is a stream wrapper attached to the stream it
will emit an unexpected warning. This is unexpected because we're not _using_ the stream in an
invalid way, we're testing so we don't use the stream in an invalid way. Possibly
specifically to avoid such an edge case or warning.
A real world impact of this is when Drupal wrapped stdout for some test suite interactions and
Symfony's deprecation handler tests stdout before writing colors to it.
https://github.com/symfony/symfony/pull/43149
This happens because isatty delegates the logic to casting and casting has this edge case where it
emits the warning.
Test script:
---------------
<?php
// https://3v4l.org/0EHT4
class strtoupper_filter extends php_user_filter {
#[\ReturnTypeWillChange]
function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
$stdout = fopen('php://stdout', 'wb');
stream_filter_register('capture', strtoupper_filter::class);
stream_filter_append($stdout, 'capture');
var_export(stream_isatty($stdout));
Expected result:
----------------
It would seem the method should just return the false without emitting a warning.
Actual result:
--------------
Warning: stream_isatty(): Cannot cast a filtered stream on this system in /in/0EHT4 on line 19
Warning: stream_isatty(): Cannot cast a filtered stream on this system in /in/0EHT4 on line 19
false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81475&edit=1