php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80996 CLI Make '-B' compatible with '-r' and <file>
Submitted: 2021-04-27 15:20 UTC Modified: 2021-04-27 15:22 UTC
From: mdw_php dot net at de-weerd dot name Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: 7.4.16 OS: Debian/Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mdw_php dot net at de-weerd dot name
New email:
PHP Version: OS:

 

 [2021-04-27 15:20 UTC] mdw_php dot net at de-weerd dot name
Description:
------------
Make '-B' and '-E' CLI options compatible with the '-r' and '<file>' arguments.

Only '-R' and '-F' options should imply that the CLI expects input.

This is usefull to run some code settings before the main script to enable some options (-B "define('DEBUG_CLASS','1')" for instance).

Test script:
---------------
Running 
   php -B 'echo 1;' -r 'echo 0;'
Returns
   Either execute direct code, process stdin or use a file.

Running (with 'test.php' containing '<? echo 0;'
   php -B 'echo 1;' test.php

Expects input were 'php test.php' does not .


On a side note, 
   echo | php -B 'echo 1;' -R 'echo 0;'


Expected result:
----------------
PHP runs the code specified in '-B' and '-E' would be run around any other code, either specified through '-r', '-R', '<file>'.

Currently '-B' seems to imply that input should be parsed, but IMHO only '-R' (and -F) should imply that.

To compare with perl:
  perl -e 'BEGIN{print 1;} print 0;'

will print 10 and exit.

and 
  perl -e 'BEGIN{print 1;} print 0;' -p

will print 1 at the start and 0 for every input line.

The presence of "BEGIN" does not imply a loop.  



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-27 15:22 UTC] mdw_php dot net at de-weerd dot name
-Summary: CLI Make '-B' incompatible with '-r' and <file> +Summary: CLI Make '-B' compatible with '-r' and <file>
 [2021-04-27 15:22 UTC] mdw_php dot net at de-weerd dot name
Corrected Summary.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC