#46359 [Com]: getopt fails to recognize '?' as a short option
ID: 46359
Comment by: RQuadling at GMail dot com
Reported By: johnston dot joshua at gmail dot com
Status: Open
Bug Type: Documentation problem
Operating System: OS X 10.5.x and OpenSuSE
PHP Version: Irrelevant
New Comment:
Also, if the short options list is something like ...
'h?r'
the 'r' option is not allowed.
<?php
$options = getopt('h?r');
?>
outputs ...
Array
(
)
when using ...
php testopt.php -r
Previous Comments:
------------------------------------------------------------------------
[2009-04-22 10:18:23] RQuadling at GMail dot com
The parse_opts() function in php-src/ext/standard/basic_functions.c
is responsible for this issue.
Only 0-9, a-z and A-Z are acceptable characters for short options.
It is odd that --? is supported if '?' is a long option.
This 1 line change patch below should cover it.
Index: basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.952
diff -u -r1.952 basic_functions.c
--- basic_functions.c 26 Mar 2009 20:02:28 -0000 1.952
+++ basic_functions.c 22 Apr 2009 10:17:31 -0000
@@ -4125,6 +4125,7 @@
memset(paras, 0, sizeof(opt_struct) * count);
*result = paras;
while ( (*opts >= 48 && *opts <= 57) || /* 0 - 9 */
+ (*opts == 63) || /* ? */
(*opts >= 65 && *opts <= 90) || /* A - Z */
(*opts >= 97 && *opts <= 122) /* a - z */
) {
------------------------------------------------------------------------
[2008-10-21 20:25:46] johnston dot joshua at gmail dot com
Description:
------------
getopt() accepts a "?" character as a short option but does not return
it if it is present in argv. It doesn't say anywhere in the manual about
? being a special character or which characters are accepted. It is
common practice to use -h/-? as options that mean show the help
I don't know if this is a documentation error or function error.
Reproduce code:
---------------
<?php
var_dump(getopt('?'));
Expected result:
----------------
jjohnston@devws37:~> php test.php -?
array(0) {
["?"]=>
bool(false)
}
Actual result:
--------------
jjohnston@devws37:~> php test.php -?
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46359&edit=1
Thread (4 messages)