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

Bug #9583 Console Args isDefined not working correctly
Submitted: 2006-12-08 15:54 UTC
From: erudd at netfor dot com Assigned: mansion
Status: Closed Package: Console_Getargs (version 1.3.4)
PHP Version: 5.1.6 OS: Fedora Core 6 x86_64
Roadmaps: (Not assigned)    
Subscription  


 [2006-12-08 15:54 UTC] erudd at netfor dot com (Edward Rudd)
Description: ------------ The fix for bug #9252 has now broken several of my applications. The scenario: I have this piece in my config array. 'export' => array( 'min'=>1, 'max'=>1, 'desc'=>"Export data for this company"), 'import' => array( 'min'=>1, 'max'=>1, 'desc'=>"Import data for this company"), But I only want to require import OR export (XOR) and I was doing a check in the PEAR::isError else to test that scenario. Now I changed my script to specify a default of '' for those two args and my "else" check is now hit, however doesn't work correctly as BOTH import and export are now "defined" even though I only specified one of them. Test script: --------------- require_once "PEAR.php"; require_once "Console/Getargs.php"; $args =& Console_Getargs::factory($config = array( 'export' => array( 'min'=>1, 'max'=>1, 'desc'=>"Export data for this company"), 'import' => array( 'min'=>1, 'max'=>1, 'desc'=>"Import data for this company"), )); if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo Console_Getargs::getHelp($config, null, $args->getMessage())."\n"; } elseif ($args->getCode() === CONSOLE_GETARGS_HELP) { echo Console_Getargs::getHelp($config)."\n"; } exit; } elseif ((!$args->isDefined('export') && !$args->isDefined('import')) || ($args->isDefined('export') && $args->isDefined('import'))) { echo Console_Getargs::getHelp($config, null, "\nMust specify either --export OR --import")."\n\n"; echo "dump:".$args->isDefined('export')."\n"; echo "dump:".$args->isDefined('import')."\n"; exit; } Expected result: ---------------- only the variables specified on the command line should be "defined" Actual result: -------------- all variables are being treated as "defined"

Comments

 [2006-12-08 16:10 UTC] wenz (Christian Wenz)
I am currently on the road and cannot test this, but did you try a default value of null instead of the empty string?
 [2006-12-08 19:24 UTC] erudd at netfor dot com
I tried that. It gave the same result as if I didn't specify them. (I screwed up my test case, as both config items are supposed to have 'default'=>'', in them)
 [2008-04-05 20:05 UTC] cweiske (Christian Weiske)
my patch requires the patch in bug #13605 to be applied, since it extends the unit tests.
 [2010-10-11 19:15 UTC] jespino (Jesús Espino)
-Status: Analyzed +Status: Closed
This bug has been fixed in SVN. 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.