Issues

ZF-2064: Zend_Console_Getopt => method addRules() fails

Issue Type: Bug Created: 2007-10-14T07:45:13.000+0000 Last Updated: 2008-11-13T14:10:04.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Carsten Möhrke (donnerchen) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Console_Getopt

Related issues: Attachments:

Description

Using addRules() result in some warnings.

reproduce code (example from the manual):

<pre class="literal">
require_once 'Zend/Console/Getopt.php';

$opts = new Zend_Console_Getopt('abp:');
$opts->addRules(
  array(
    'verbose|v' => 'Print verbose output'
  )
);

Output:

<pre class="literal">
PHP Warning:  preg_match_all() expects parameter 2 to be string, array given in /Users/carsten/Sites/Zend/Console/Getopt.php on line 814

Warning: preg_match_all() expects parameter 2 to be string, array given in /Users/carsten/Sites/Zend/Console/Getopt.php on line 814
PHP Notice:  Undefined offset:  1 in /Users/carsten/Sites/Zend/Console/Getopt.php on line 815

Notice: Undefined offset:  1 in /Users/carsten/Sites/Zend/Console/Getopt.php on line 815
PHP Warning:  Invalid argument supplied for foreach() in /Users/carsten/Sites/Zend/Console/Getopt.php on line 815

Warning: Invalid argument supplied for foreach() in /Users/carsten/Sites/Zend/Console/Getopt.php on line 815

Comments

Posted by Thomas Weidner (thomas) on 2007-10-15T13:44:00.000+0000

Assigned to Bill

Posted by Benjamin Eberlei (beberlei) on 2008-11-07T06:01:46.000+0000

This issue steems from a badly engineered switching between ZEND and GNU Modes.

Zend_Console_GetOpt works with two modes on options MODE_ZEND and MODE_GNU. What happens in the above example is the following:

In the constructor arguments are created in MODE_GNU. Console_GetOpt recognizes that and reverts its setting from MODE_ZEND (default) to MODE_GNU. Now when the addRules() is called with v|verbose Console_GetOpt is still in MODE_GNU and tries to add the array accordingly which fails.

The fix for this issue is very simple and just consists of not switching to MODE GNU when first adding a string then an array.

I suggest a refactoring to strategy pattern to fix the strange switch statement. I will add an issue for this.

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:04.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts