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  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 32 - 6 = ?

 
 [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] cellog (Greg Beaver)
the documentation is clear on this: options cannot be substrings of other options, or it is ambiguous. Try two_last_name=
 [2006-12-23 03:02 UTC] andrei (Andrei Zmievski)
I think this is worth implementing if we can unambiguously distinguish long option names. The provided patch is okay, but could be improved (like the preg_replace() stuff).
 [2007-02-01 05:27 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.