Skip to content

STDIN/STDOUT/STDERR is not available for CLI without a script #11104

Closed
ThePHPF/thephp.foundation
#90

Description

@jhdxr

Description

I ran into this issue when I try to access STDOUT with Symfony\Component\Process\PhpProcess
I dig a bit and found out the three stream constants are not available for CLI are not available without a script or certain options (.e.g -a or -r)

Here is a simplied way to reproduce.

~> php
<?php var_dump(STDOUT);
<ctrl+d>

Resulted in this output:

PHP Fatal error:  Uncaught Error: Undefined constant "STDOUT" in Standard input code:1
Stack trace:
#0 {main}
  thrown in Standard input code on line 1

But I expected this output instead:

resource(2) of type (stream)

I try to trace why there is such constraint but it seems to be there for more than 10 years. Shall we fix it or document this behavior?

PHP Version

PHP 8.2.4

Operating System

irrelevant

Activity

  1. iluuu1994 commented on Apr 19, 2023

    @iluuu1994
    Member

    Related to #10673.

  2. thg2k commented on Apr 20, 2023

    @thg2k
    Contributor

    I can confirm this from ancient PHP versions, so it is not related to preloading/opcache, it has always been this way.

  3. added a commit that references this issue on Apr 30, 2023
    5c0102f
  4. added a commit that references this issue on Jul 19, 2024
    f6c0c60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions