Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.3

Bug #10055 Not failing properly on short options missing required values
Submitted: 2007-02-08 17:43 UTC
From: jjohnston at mailwise dot com Assigned: cellog
Status: Closed Package: Console_Getopt (version 1.2.1)
PHP Version: 4.4.4 OS: SuSE 9.2
Roadmaps: (Not assigned)    
Subscription  


 [2007-02-08 17:43 UTC] jjohnston at mailwise dot com (Joshua Johnston)
Description: ------------ Depending on the order that command line options are passed, it is possible to 'bypass' a required value for a short option which erroneously assigns another option as the value to the previous option. Test script: --------------- <?php // filename test.php require_once 'Console/Getopt.php'; $options = new Console_Getopt(); $ret = $options->getopt($options->readPHPArgv(), 'i:r::l', array('file=','test==')); if(PEAR::isError($ret)) { die($ret->getMessage()."\n"); } else { var_dump($ret); } ?> Correct results $ php test.php -l -i Incorrect results $ php test.php -i -l Expected result: ---------------- $ php test.php -l -i # Behaves correctly $ php test.php -i -l Console_Getopt: option requires an argument -- i Because -i is missing its value and -l is a different option. Actual result: -------------- # Incorrect behavior $ php test.php -i -l array(2) { [0]=> array(1) { [0]=> array(2) { [0]=> string(1) "i" [1]=> string(2) "-l" } } [1]=> array(0) { } } # Correct behavior $ php test.php -l -i Console_Getopt: option requires an argument -- i

Comments

 [2007-02-18 04:13 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.