unread
Hello all,
Many getopt implementations expose an optind
variable to userland
which contains the last argv index examined by the option parser. This
is useful when mixing flag arguments with positional arguments, as it
makes locating the positional arguments easy.
For example, in C and Bash...
./test -a 1 -b 2 file1 file2
After option parsing finishes, optind
is 5 ("file1").
PHP's getopt implementation already uses an optind
variable under
the hood. I propose exposing this value via an optional by-ref param
on getopt
. It would look like this:
# php test.php -a 1 -b 2 file1 file2
$optind = null;
getopt('a:b:', [], $optind);
var_dump($optind); // int(5)
I'm hoping to gather feedback on this idea before submitting an RFC.
Patch is here:
https://github.com/php/php-src/compare/master...adsr:getopt-optind
Thanks,
Adam