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

Bug #4475 An ambiguous error occurred when specifying similar longoption name.
Submitted: 2005-05-30 09:57 UTC
From: ryo at fastriver dot net Assigned: cellog
Status: Closed Package: Console_Getopt
PHP Version: 4.3.11 OS: Slackware Linux 9.0
Roadmaps: (Not assigned)    
Subscription  


 [2005-05-30 09:57 UTC] ryo at fastriver dot net
Description: ------------ I'm a Japanese. I'm sorry, my English is poor, so it may be hard to read this. For example, I give the following similar longoptions parameter to getopt(). $longoptions = array("last_name=", "last_name_two="); And I execute my php script as follows. php myscript.php --last_name="abc" Then, getopt() return a PEAR error object. The error message of the error object is as follows. Console_Getopt: option --last_name is ambiguous Reproduce code: --------------- --- Getopt.php.orig 2003-12-12 04:21:14.000000000 +0900 +++ Getopt.php 2005-05-30 18:43:51.000000000 +0900 @@ -201,7 +201,7 @@ options. */ if ($opt_rest != '' && $opt{0} != '=' && $i + 1 < count($long_options) && - $opt == substr($long_options[$i+1], 0, $opt_len)) { + $opt == substr($long_options[$i+1], 0, strlen($long_options[$i+1]))) { return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous"); } Expected result: ---------------- getopt() should not return the error object. Actual result: -------------- getopt() returns the error object.

Comments

 [2006-07-26 07:07 UTC] mleegwater at gmail dot com (Michiel Leegwater)
Hi there! A patch that could solve this problem: --- /usr/share/php/Console/Getopt.php 2006-04-16 13:19:46.000000000 +0200 +++ Getopt.php 2006-07-26 08:50:57.000000000 +0200 @@ -189,19 +189,21 @@ for ($i = 0; $i < count($long_options); $i++) { $long_opt = $long_options[$i]; - $opt_start = substr($long_opt, 0, $opt_len); + $long_opt_name = preg_replace("/=/", "", $long_opt); - /* Option doesn't match. Go on to the next one. */ - if ($opt_start != $opt) - continue; + if ($long_opt_name != $opt) + continue; $opt_rest = substr($long_opt, $opt_len); /* Check that the options uniquely matches one of the allowed options. */ + $next_option_rest = substr($long_options[$i+1],$opt_len); if ($opt_rest != '' && $opt{0} != '=' && $i + 1 < count($long_options) && - $opt == substr($long_options[$i+1], 0, $opt_len)) { + $opt == substr($long_options[$i+1], 0, $opt_len) && + $next_option_rest != '' && + $next_option_rest{0} != '=') { return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous"); } Regards, Michiel
 [2006-12-23 02:05 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-12-23 03:02 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-02-01 05:27 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!