Bug #81475 [Opn->Ver]: stream_isatty emits warning with attached stream wrapper

From: Date: Fri, 24 Sep 2021 15:07:01 +0000
Subject: Bug #81475 [Opn->Ver]: stream_isatty emits warning with attached stream wrapper
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236817@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: cmb@php.net Reported by: neclimdul at gmail dot com Summary: stream_isatty emits warning with attached stream wrapper -Status: Open +Status: Verified Type: Bug Package: Streams related Operating System: any PHP Version: 8.1.0RC2 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#236817) next »