From: php at richardneill dot org Operating system: PHP version: 5.4.13 Package: CGI/CLI related Bug Type: Feature/Change Request Bug description:Allow open tag to "discard the previous shebang"
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. -- Edit bug report at https://bugs.php.net/bug.php?id=64488&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64488&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64488&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64488&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64488&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64488&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64488&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64488&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64488&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64488&r=support Expected behavior: https://bugs.php.net/fix.php?id=64488&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64488&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64488&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64488&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64488&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64488&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64488&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64488&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64488&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64488&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64488&r=mysqlcfg