Skip to content

workaround of "Option X is unknown" exception (may be duplicate to #45)

Thomas Flori requested to merge github/fork/vikijel/vikijel into master

Created by: vikijel

$strict parameter => workaround of "Option X is unknown" exception

this allows stuff like this: script.php -o nextoption --nextoption="Hello world!" =>

$option1 = ['o'];
$getopt->addOption($option1);
$getopt->parse(null, false); // No exception is called despite more than one defined option is present in command, parses value of option 'o'
$option1_value = $getopt->getOption('o'); //I actually needed to get name of class from one option and then get more option definions from that class
$getopt->addOption([$option1_value]); //add definition of 'nextoption'
$getopt->parse(); //parse value of options 'o' and 'nextoption'
echo $getopt->getOption($option1_value); //value of dynamically defined option 'nextoption' based on option1 available after reparsing command

Merge request reports