FAQ
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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedMay 29, '16 at 6:58p
activeMay 29, '16 at 6:58p
posts1
users1
websitephp.net

1 user in discussion

As: 1 post

People

Translate

site design / logo © 2018 Grokbase