php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36060 `--' end arguments terminator incorrectly sent to script (CGI only)
Submitted: 2006-01-17 22:53 UTC Modified: 2006-01-17 23:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: support-forums4 at farmdev dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.1.2 OS: FreeBSD
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: support-forums4 at farmdev dot com
New email:
PHP Version: OS:

 

 [2006-01-17 22:53 UTC] support-forums4 at farmdev dot com
Description:
------------
see test script, run it like ...

$ php -f test_end_arg.php -- -h -f

PHP should execute the script as the equivalent of `test_end_arg.php -h -f`.  This works in the cli version of php but not the cgi version (from command line).  Sorry I couldn't test on more versions.

Cli version I tested with (PASSED) was :

====================
PHP Version => 5.0.4

System => Linux dev 2.4.18-1-686 #1 Wed Apr 14 18:20:10 UTC 2004 i686
Build Date => May 12 2005 14:12:56
Configure Command =>  './configure' '--prefix=/vol2/php5' '--with-apxs=/vol2/php5/bin/apxs' '-with-config-file-scan-dir=/vol2/php5/lib/php' '--enable-shared' '--with-zlib=shared' '--with-curl=shared,/vol2/php5' '--with-mcrypt=shared,/vol2/php5' '--with-mhash=shared,/vol2/php5' '--with-openssl=shared' '--with-gettext=shared' '--with-gd=shared' '--enable-wddx=shared' '--with-jpg-dir=/usr' '--with-png-dir=/usr' '--enable-dba=shared' '--with-mysql=shared,/usr/local/mysql' '--with-pgsql=shared,/usr/local/pgsql' '--enable-soap=shared' '--enable-sysvshm=shared' '--enable-sysvmsg=shared' '--enable-sysvsem=shared' '--with-libxml-dir=/vol2/php5'
Server API => Command Line Interface
====================================

CGI version I tested with (FAILED) was :

====================================
PHP Version 5.0.5

System 	FreeBSD dev2.leapfrogonline.com 4.11-RELEASE FreeBSD 4.11-RELEASE #0: Fri Ja i386
Build Date 	Sep 22 2005 16:22:00
Configure Command 	'./configure' '--enable-versioning' '--enable-memory-limit' '--with-layout=GNU' '--with-config-file-scan-dir=/usr/local/etc/php' '--disable-all' '--enable-libxml' '--with-libxml-dir=/usr/local' '--enable-spl' '--with-regex=php' '--disable-cli' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-fastcgi' '--prefix=/usr/local' 'i386-portbld-freebsd4.11'
Server API 	CGI/FastCGI
====================================

Reproduce code:
---------------
test_end_arg.php:
<?php
print_r($_SERVER['argv']);
assert( !in_array('--',$_SERVER['argv']));
?>

Expected result:
----------------
// see description about how to run the script
Array
(
    [0] => test_end_arg.php
    [1] => -h
    [2] => -f
)

Actual result:
--------------
PHP Warning:  assert() [<a href='function.assert'>function.assert</a>]: Assertion failed in /home/kumar/tmp/test_end_arg.php on line 3
Array
(
    [0] => test_end_arg.php
    [1] => --
    [2] => -h
    [3] => -f
)
<br />
<b>Warning</b>:  assert() [<a href='function.assert'>function.assert</a>]: Assertion failed in <b>/home/kumar/tmp/test_end_arg.php</b> on line <b>3</b><br />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-17 22:56 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2006-01-17 22:58 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Command line parsing is different between those two SAPIs. You should only use the CLI for command line work... as that\'s what it was meant for.
 [2006-01-17 23:07 UTC] support-forums4 at farmdev dot com
I understand it's not ideal that our server uses the cgi version from the command line but it is confusing that php includes `--' in the arguments when it has already gone so far as to pass through the extra arguments.  In other words, if cgi should *never* be used on the command line, why doesn't:

$ php -f test_end_arg.php -- -f -p

simply produce:
Array
(
    [0] => test_end_arg.php
)

?  I think we can agree that the cgi version should be able to work from the command line.  On the other hand, I'm sure there are a million more important bugs to fix ... but this did trip me up for a while and seems trivial to fix.

thanks, Kumar
 [2006-01-17 23:16 UTC] derick@php.net
No, the CGI should not be used on the command line - there are other reasons why you shouldn't do this. Use the CLI (stands for Command Line Interface) for command line work.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC