From: php at richardneill dot org Operating system: Linux (Mandrake) PHP version: 4.3.4 PHP Bug Type: CGI related Bug description: getopt parses incorrectly
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 bug report at http://bugs.php.net/?id=26818&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26818&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26818&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26818&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26818&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26818&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26818&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26818&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26818&r=support Expected behavior: http://bugs.php.net/fix.php?id=26818&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26818&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26818&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26818&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26818&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26818&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26818&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26818&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26818&r=float