From:             addw at phcomp dot co dot uk
Operating system: all
PHP version:      Irrelevant
Package:          CGI/CLI related
Bug Type:         Feature/Change Request
Bug description:getopt: cannot report bad options or how much of argv used

Description:
------------
Getopt has 2 deficiencies that make it hard to use at the command line:

1) If an illegal option is used on the command line, this is not reported
to the PHP script. This means that an error/... message cannot be
generated.

2) Most programs will expect arguments after the options. getopt() does not
let the application know how many elements in argv have been used by
options. The Unix getopt(3) will put this number in the global variable
'optind'.

Both of these could be remedied by there being 2 extra elements where the
keys are:
'optind' -- number of elements used from argv;
'badopts' -- an array that contains the options that were not recognised.
Since this might confuse existing programs I suggest that these 2 extra
elements only by created if the getopt $options argument string starts with
a ':'.

Test script:
---------------
<?php

$optstring = "ab:";

echo "optstring='$optstring'\n";
$args = getopt($optstring);
var_dump($args);
?>

Run it:

php test.php -a -q -b ff -bxx ffff

Note that '-q' is not reported as a bad argument. There is no indication
that '-bxx' is the last argument.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=65673&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65673&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65673&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65673&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65673&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65673&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65673&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65673&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65673&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65673&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65673&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65673&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65673&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65673&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65673&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65673&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65673&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65673&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65673&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65673&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65673&r=mysqlcfg

Reply via email to