I've trying the following examples such as:
$ php -r 'require_once($argv[1]);' <(echo "hello")
or:
$ php -r 'file_get_contents($argv[1]);' <(echo "hello")
both fails like:
PHP Warning: require_once(/dev/fd/63): failed to open stream: No such file or directory in Command line code on line 1
PHP Warning: file_get_contents(/dev/fd/63): failed to open stream: No such file or directory in Command line code on line 1
or:
$ php -r 'file_get_contents($argv[0]);' < <(echo "hello")
which fails with:
PHP Fatal error: require_once(): Failed opening required '-' (include_path='.:/usr/share/pear:/usr/share/php') in Command line code on line 1
The above attempts were inspired by drush
command, for example:
$ drush --early=<(echo print 123';') ""
[warning] require_once(/dev/fd/63): failed to open stream: No such file or directory preflight.inc:58
where I could inject the dynamic PHP code from the file descriptor (without creating a separate file each time) in order to execute the code before bootstrapping the main code.
Other similar command tools works correctly:
$ cat <(echo "hello")
hello
or:
$ python -c "import sys; print sys.stdin.readlines()" < <(echo "hello")
['hello\n']
I've found this PHP bug and this one, but these has been fixed long time ago and I'm using 5.6.22.
Is there any way that I can trick PHP into reading data from the process substitution (to read from file descriptor , e.g. /dev/fd
) when called from CLI, by using some simple one-liner?