Skip to content

Commit 94efe53

Browse files
committed
Clean up the argv array after getopt
1 parent e6b3f62 commit 94efe53

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

phpctags

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ $options = getopt('af:Nno:RuV', array(
2525
'memory::',
2626
));
2727

28+
// prune options and its value from the $argv array
29+
$argv_ = array();
30+
foreach ($options as $option => $value) {
31+
foreach ($argv as $key => $chunk) {
32+
$regex = '/^'. (isset($option[1]) ? '--' : '-') . $option . '/';
33+
if ($chunk == $value && $argv[$key-1][0] == '-' || preg_match($regex, $chunk)) {
34+
array_push($argv_, $key);
35+
}
36+
}
37+
}
38+
while ($key = array_pop($argv_)) unset($argv[$key]);
39+
2840
// option -V is an alternative to --version
2941
if (isset($options['V'])) {
3042
$options['version'] = FALSE;

0 commit comments

Comments
 (0)