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

Bug #9583 Console Args isDefined not working correctly
Submitted: 2006-12-08 10:54 UTC Modified: 2008-05-10 22:54 UTC
From: erudd at netfor dot com Assigned: mansion
Status: Analyzed Package: Console_Getargs (version 1.3.4)
PHP Version: 5.1.6 OS: Fedora Core 6 x86_64
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: erudd at netfor dot com
New email:
PHP Version: Package Version: OS:

 

 [2006-12-08 10: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 11: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 14: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 15:05 UTC] cweiske (Christian Weiske)
my patch requires the patch in bug #13605 to be applied, since it extends the unit tests.