php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64488 Allow open tag to "discard the previous shebang"
Submitted: 2013-03-22 10:32 UTC Modified: 2013-09-30 12:13 UTC
From: php at richardneill dot org Assigned:
Status: Duplicate Package: CGI/CLI related
PHP Version: 5.4.13 OS:
Private report: No CVE-ID: None
 [2013-03-22 10:32 UTC] php at richardneill dot org
Description:
------------
It would be really useful to be able to write single files that would run cleanly 
as *either* CGI or CLI scripts. 

At the moment, the closing '?>' tag will eat the trailing newline.

So, similarly, I'd like to request a way for the opening '<?' tag to eat the 
previous literal shebang line.

Test script:
---------------
#!/usr/bin/php
<?
if (php_sapi_name()== "cgi"){
   erase_previous_line()       <-- hypothetical function.
   echo "I am CGI<br>";
}else{
   echo "I am CLI\n";
}
?>

Expected result:
----------------
Exactly one line should be printed: 
  "I am CLI|CGI"

Actual result:
--------------
In CLI mode, this script cleanly prints:
  "I am CLI"
but in Apache mode, the script prints the first line literally:
  "#!/usr/bin/php
   I am CGI<br>"


It's relatively easy to work around this with a wrapper script, but I'd 
appreciate the elegance of having a single file that can operate in both modes.
Thank you for your time.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-22 23:46 UTC] bobwei9 at hotmail dot com
It's principally a good idea, but a function is very complicated to realize as the shebang is already sent when the function will be called.

What I'd prefer is erasing the shebang line every time in a non-cli script when the two first bytes are '#' and '!'. (I'd wonder if there exist some people who really begin the content of their websites with a #!...)
 [2013-09-30 12:13 UTC] mike@php.net
-Status: Open +Status: Duplicate
 [2013-09-30 12:13 UTC] mike@php.net
See req #31563
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu May 23 23:01:26 2019 UTC