Skip to content

Arguments should not require a space before the value

Created by: Firehed

Traditional getopt usage (across most languages, not just PHP's native implementation) doesn't require a space between short arguments and their values. This library does, which is inconsistent with expected behavior.

Expected/traditional behavior:

$ php ngo.php -a -bb -c
Array
(
    [a] => 
    [b] => b
    [c] => 
)

$ cat ngo.php 
<?php
print_r(getopt('ab:c::'));

Actual result:

$ php go.php -a -bb -c
Option 'b' must have a value
$ cat go.php 
<?php
require_once 'vendor/autoload.php';

$g = new Ulrichsg\Getopt\Getopt('ab:c::');
try {
    $g->parse();
    print_r($g->getOptions());
} catch (\Exception $e) {
    echo $e->getMessage();
    exit(1);
}

(I'll take a stab at a PR to fix this as well)