php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43283 CLI does not define STDOUT/STDERR with stdin script
Submitted: 2007-11-13 23:31 UTC Modified: 2007-11-21 11:40 UTC
From: lbayuk at pobox dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lbayuk at pobox dot com
New email:
PHP Version: OS:

 

 [2007-11-13 23:31 UTC] lbayuk at pobox dot com
Description:
------------
When using the PHP CLI executable, the script can be named on the command line, or fed to PHP through standard input. If using standard input, the file constants STDIN, STDOUT, and STDERR are undefined.  I can understand not defining STDIN, since the script is read from there, but why are STDOUT and STDERR not defined?


Reproduce code:
---------------
<?php
fwrite(STDOUT, "Hello, standard output\n");
fwrite(STDERR, "Hello, standard error\n");


Expected result:
----------------
Written to stdout:  Hello, standard output
Written to stderr:  Hello, standard error


Actual result:
--------------
When run as: $ php nostd.php
   Works as expected.

When run as: $ php < nostd.php
   This output:
PHP Notice:  Use of undefined constant STDOUT - assumed 'STDOUT' in ...
PHP Warning:  fwrite(): supplied argument is not a valid stream resource in...
PHP Notice:  Use of undefined constant STDERR - assumed 'STDERR' in ...
PHP Warning:  fwrite(): supplied argument is not a valid stream resource in ...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-14 01:29 UTC] johannes@php.net
I once tried to fix that but it just lead to crazy problems, therefore making this a documentation issue.
 [2007-11-21 11:40 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"These constants are not available in case of reading PHP script from stdin."
 [2018-06-15 06:42 UTC] robberphex at gmail dot com
This bug still exists!


And I submit pr to fix: https://github.com/php/php-src/pull/3305
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 28 10:01:29 2025 UTC