ID:               26818
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php at richardneill dot org
-Status:           Open
+Status:           Bogus
 Bug Type:         CGI related
 Operating System: Linux (Mandrake)
 PHP Version:      4.3.4
 New Comment:

RTFM: "It does not matter if an argument has leading white space." (it
means also: whitespace is omitted)



Previous Comments:
------------------------------------------------------------------------

[2004-01-06 14:52:41] php at richardneill dot org

Description:
------------
When parsing options, if the command line arguments are WRONG, php
mangles them in such a way as to give an incorrect, but valid
response.

Eg my program normally takes arguments:
      ./getopt.php -a -x foo -y bar
(ie. option a takes no value; options x,y take values)

Therefore, if I run it as
       ./getopt.php -a -x -y bar
this is clearly a mistake: I omitted the value for -x.

HOWEVER, php assumes that I wanted the value for -x to be '-y'

If this is "a feature, not a bug", it might be worth documentig it, or
providing a switch to enable the behaviour I'd expect. Thank you.


Reproduce code:
---------------
#!/usr/bin/php
<?
$flags="ax:y:";
$options_array=getopt($flags);

echo "Here are the results of getopt:\n";

foreach ($options_array as $key => $value){
        echo "\tkey:\t $key\t value is:\t $value";
        if ($value===false){
                echo "\t[FALSE]";
        }
        echo "\n";
}
echo "\n";

#N.B. If options -x and -y each expect an argument, then one might
expect
# 'getopt.php -x -y foo' to result in $key="x",$value=false;
$key="y",$value="foo"
# BUT actually, the result is $key="x",$value="-y"; and foo is left
over.


Expected result:
----------------
[rjn]$ ./getopt.php -a -x -y bar
Here are the results of getopt:
        key:     a       value is:              [FALSE]
        key:     x       value is:              [FALSE]      
        key:     y       value is:       bar

Actual result:
--------------
[rjn]$ ./getopt.php -a -x  -y bar
Here are the results of getopt:
        key:     a       value is:              [FALSE]
        key:     x       value is:       -y




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26818&edit=1

Reply via email to