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

Fetching Options by Name

You can use the getOption() method to query the value of an option. If the option had a parameter, this method returns the value of the parameter. If the option had no parameter but the user did specify it on the command-line, the method returns TRUE. Otherwise the method returns NULL.

Example 125. Using getOption()

<?php
$opts 
= new Zend_Console_Getopt('abp:');
$b $opts->getOption('b');
$p_parameter $opts->getOption('p');

Alternatively, you can use the magic __get() function to retrieve the value of an option as if it were a class member variable. The __isset() magic method is also implemented.

Example 126. Using __get() and __isset() Magic Methods

<?php
$opts 
= new Zend_Console_Getopt('abp:');
if (isset(
$opts->b)) {
    echo 
"I got the b option.\n";
}
$p_parameter $opts->p// null if not set

If your options are declared with aliases, you may use any of the aliases for an option in the methods above.

Zend Framework