Skip to content
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

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

Closed
jhdxr opened this issue Apr 19, 2023 · 2 comments · Fixed by ThePHPF/thephp.foundation#90
Closed

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

jhdxr opened this issue Apr 19, 2023 · 2 comments · Fixed by ThePHPF/thephp.foundation#90

Comments

@jhdxr
Copy link
Member

jhdxr commented Apr 19, 2023

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

@iluuu1994
Copy link
Member

Related to #10673.

@thg2k
Copy link
Contributor

thg2k commented Apr 20, 2023

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

nielsdos added a commit to nielsdos/php-src that referenced this issue Apr 30, 2023
… a script

I found no reason why this is done this way.
Of course this will allow users to do stupid stuff like
`fclose(STDOUT);` etc. but if they type in that code they clearly know
what they're doing...
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.

3 participants