Hi.
I was working on the project and needed to write console command to do some stuff.
I needed to work with options and I decided to use getopt.
But I faced unexpected problem, getopt returns empty array.
Here is the sample code of run method:
$options = 'd:u:p::c:';
$longoptions = array(
'database:',
'user:',
'password::',
'config:'
);
$parameters = getopt($options, $longoptions);
var_dump($parameters);
And here is the output:
protected/yiic somescript -d test
array(0) {
}
If parameters set was wrong, I would simply get false.
I’ve put the same code into raw php file and it works well.
$ php /tmp/test.php -d test
array(1) {
'd' =>
string(4) "test"
}
Here is the content:
$ cat /tmp/test.php
<?php
$options = 'd:u:p::c:';
$longoptions = array(
'database:',
'user:',
'password::',
'config:'
);
$parameters = getopt($options, $longoptions);
var_dump($parameters);
What am I doing wrong and how can this be solved?