Index: library/Zend/Console/Getopt.php =================================================================== --- library/Zend/Console/Getopt.php (revision 19739) +++ library/Zend/Console/Getopt.php (working copy) @@ -344,10 +344,16 @@ * These are appended to those defined when the constructor was called. * * @param array $argv + * @throws Zend_Console_Getopt_Exception When not given an array as parameter * @return Zend_Console_Getopt Provides a fluent interface */ public function addArguments($argv) { + if(!is_array($argv)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Parameter #1 to addArguments should be an array"); + } $this->_argv = array_merge($this->_argv, $argv); $this->_parsed = false; return $this; @@ -358,10 +364,16 @@ * These replace any currently defined. * * @param array $argv + * @throws Zend_Console_Getopt_Exception When not given an array as parameter * @return Zend_Console_Getopt Provides a fluent interface */ public function setArguments($argv) { + if(!is_array($argv)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Parameter #1 to setArguments should be an array"); + } $this->_argv = $argv; $this->_parsed = false; return $this; Index: tests/Zend/Console/GetoptTest.php =================================================================== --- tests/Zend/Console/GetoptTest.php (revision 19739) +++ tests/Zend/Console/GetoptTest.php (working copy) @@ -278,6 +278,32 @@ unset($opts->a); $this->assertFalse(isset($opts->a)); } + + /** + * @group ZF-5948 + */ + public function testGetoptAddSetNonArrayArguments() + { + $opts = new Zend_Console_GetOpt('abp:', array('-foo')); + try { + $opts->setArguments('a'); + } catch(Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); + $this->assertEquals("Parameter #1 to setArguments should be an array", + $e->getMessage()); + } + + try { + $opts->addArguments('-b'); + } catch(Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); + $this->assertEquals("Parameter #1 to addArguments should be an array", + $e->getMessage()); + } + + } public function testGetoptAddArguments() {