Edit report at https://bugs.php.net/bug.php?id=62940&edit=1
ID: 62940
User updated by: b8kich at gmail dot com
Reported by: b8kich at gmail dot com
Summary: getopt does not support long options without short
options
-Status: Open
+Status: Closed
Type: Bug
Package: PHP options/info functions
Operating System: Linux (Centos 6.3)
PHP Version: 5.4.6
Block user comment: N
Private report: N
New Comment:
Getopt stops parsing on the unrecognized (short) option as documented.
Previous Comments:
------------------------------------------------------------------------
[2012-08-31 15:12:27] b8kich at gmail dot com
I see the issue is I had an extra option before the long options in the command
I've used to test. Getopt stops parsing on the unrecognized option. This is
actually documented, let's close this out.
$ php script.php -f "value for f" --required value --optional="optional value"
--option
------------------------------------------------------------------------
[2012-08-30 20:26:34] lonnyk at gmail dot com
I am not having any problems with this:
$ php -v
PHP 5.4.6RC1 (cli) (built: Aug 30 2012 20:24:11) (DEBUG)
$ php ../tests/issue-62940.php --required value --optional="optional value" --
option
array(3) {
["required"]=>
string(5) "value"
["optional"]=>
string(14) "optional value"
["option"]=>
bool(false)
}
Can you please provide the _exact_ command you are using for calling the script?
------------------------------------------------------------------------
[2012-08-26 18:37:45] b8kich at gmail dot com
Description:
------------
When only long options are required in getopt (without any short options), they
are not captured.
Found this in 5.3.15 (CentOS 5.8) and confirmed in 5.4.6 (CentOS 6.3)
Test script:
---------------
script.php:
<?php
$longopts = array(
"required:", // Required value
"optional::", // Optional value
"option", // No value
"opt", // No value
);
$options = getopt("", $longopts);
var_dump($options);
?>
Expected result:
----------------
The long options should be captured even if there are not short ones:
array(3) {
["required"]=>
string(5) "value"
["optional"]=>
string(14) "optional value"
["option"]=>
bool(false)
}
Actual result:
--------------
$ php script.php -f "value for f" --required value --optional="optional value"
--option
array(0) {
}
Throwing in some short options does not help either:
$ php script.php -f "value for f" -v -a --required value --optional="optional
value" --option
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62940&edit=1