note 107955 added to function.getopt
| From: | lynch@php.net | Date: | Fri, 16 Mar 2012 17:01:37 +0000 |
| Subject: | note 107955 added to function.getopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186706@lists.php.net to get a copy of this message | ||
In PHP < 5.3.0 you can "simulate" the "optional v::" by using this:
"vv:"
#!/usr/bin/php
<?php
$short = "vv:";
$opts = getopt($short);
var_dump($opts);
?>
./test_opt.php -v
array(1) {
["v"]=>
bool(false)
}
./test_opt.php -vv
array(1) {
["v"]=>
array(2) {
[0]=>
bool(false)
[1]=>
bool(false)
}
}
./test_opt.php -vvv
array(1) {
["v"]=>
array(3) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
}
}
./test_opt.php -vvvv
array(1) {
["v"]=>
array(4) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
}
}
I'm not sure if that's a Bug or a Feature, as it's not documented as such, but it
works for me.
I also have not tested if it works with other opts, nor if you need vv: in that exact order, or even
consecutive...
"v:v" or "vav:" (with -a being something else) etc may also work. Or not. I
leave that as an exercise for the reader.
----
Server IP: 69.147.83.197
Probable Submitter: 67.128.187.35
----
Manual Page -- http://www.php.net/manual/en/function.getopt.php
Edit -- https://master.php.net/note/edit/107955
Del: integrated -- https://master.php.net/note/delete/107955/integrated
Del: useless -- https://master.php.net/note/delete/107955/useless
Del: bad code -- https://master.php.net/note/delete/107955/bad+code
Del: spam -- https://master.php.net/note/delete/107955/spam
Del: non-english -- https://master.php.net/note/delete/107955/non-english
Del: in docs -- https://master.php.net/note/delete/107955/in+docs
Del: other reasons-- https://master.php.net/note/delete/107955
Reject -- https://master.php.net/note/reject/107955
Search -- https://master.php.net/manage/user-notes.php