php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81475 stream_isatty emits warning with attached stream wrapper
Submitted: 2021-09-24 14:38 UTC Modified: 2021-09-24 15:07 UTC
From: neclimdul at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 8.1.0RC2 OS: any
Private report: No CVE-ID: None
 [2021-09-24 14:38 UTC] 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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-24 15:07 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-09-24 15:42 UTC] 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-29 11:50 UTC] git@php.net
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
 [2021-09-29 11:50 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 21:03:36 2021 UTC