Better CLI argument processing in PHP

1.1.2 2012-12-24 12:35 UTC


#Packfire Options

Better CLI argument processing in PHP

Options helps you to parse CLI arguments using callbacks and Closures (in PHP 5.3+) effectively. Implementing the NDesk.Options (C#) in PHP, you will be able to write neat CLI applications in PHP quickly.


  • = PHP 5.3


To install Packfire Options, add the entry to your composer.json "require" section:

"packfire/options": "1.1.*"


use Packfire\Options\OptionSet;

$command = null;
$quiet = false;
$force = false;
$linker = false;
$file = '';

$options = new OptionSet();

$options->addIndex(0, function($value) use(&$command) {
            $command = $value;
$options->add('q', function() use(&$quiet) {
            $quiet = true;
$options->add('l', function() use(&$linker) {
            $linker = true;
$options->add('f', function() use(&$force) {
            $force = true;
$options->add('file=', function($value) use(&$file) {
            $file = $value;


##Projects using Packfire Options


  • Sam-Mauris Yong (@thephpdeveloper)


Packfire Options is licensed under the BSD 3-Clause License. See license file in repository for details.