[RFC] Add &$optind to getopt

From: Date: Sun, 29 May 2016 18:57:46 +0000
Subject: [RFC] Add &$optind to getopt
Groups: php.internals 
Request: Send a blank email to internals+get-93627@lists.php.net to get a copy of this message
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

« previous php.internals (#93627) next »