Skip to content

Instantly share code, notes, and snippets.

@sun
Created July 21, 2014 23:02
Show Gist options
  • Save sun/d02c242514c8f34bccdb to your computer and use it in GitHub Desktop.
Save sun/d02c242514c8f34bccdb to your computer and use it in GitHub Desktop.
PHP CLI vs. STDIN / STDOUT / STDERR — https://bugs.php.net/bug.php?id=43283
$ echo "<?php var_dump(STDOUT);" > y.stdout
$ php y.stdout
resource(2) of type (stream)
$ php -r "var_dump(STDOUT);"
resource(2) of type (stream)
$ echo "<?php var_dump(STDOUT);" | php
PHP Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 1
PHP Stack trace:
PHP 1. {main}() -:0
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 1
Call Stack:
0.0000 125824 1. {main}() -:0
string(6) "STDOUT"
$ echo "<?php var_dump(STDOUT);" > y.stdout
$ php < y.stdout
PHP Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 1
PHP Stack trace:
PHP 1. {main}() -:0
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 1
Call Stack:
0.0000 125824 1. {main}() -:0
string(6) "STDOUT"
$ php
<?php
var_dump(STDOUT);
^Z
PHP Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 2
PHP Stack trace:
PHP 1. {main}() -:0
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in - on line 2
Call Stack:
18.4301 125824 1. {main}() -:0
string(6) "STDOUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment