|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-10-21 20:25 UTC] 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) {
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Jun 15 02:00:02 2026 UTC |
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 */ ) {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