PhpRiot
Follow phpriot on Twitter
Sponsored Link
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Adding Argument Lists

By default, Zend_Console_Getopt uses $_SERVER['argv'] for the array of command-line arguments to parse. You can alternatively specify the array of arguments as the second constructor argument. Finally, you can append more arguments to those already used using the addArguments() method, or you can replace the current array of arguments using the setArguments() method. In both cases, the parameter to these methods is a simple array of strings. The former method appends the array to the current arguments, and the latter method substitutes the array for the current arguments.

Example 131. Using addArguments() and setArguments()

<?php
// By default, the constructor uses $_SERVER['argv']
$opts = new Zend_Console_Getopt('abp:');

// Append an array to the existing arguments
$opts->addArguments(array('-a''-p''p_parameter''non_option_arg'));

// Substitute a new array for the existing arguments
$opts->setArguments(array('-a''-p''p_parameter''non_option_arg'));

Zend Framework