所以,在代码中,我有这个
$availableOptions = array( 'run' => 'runs a script',
'list' => 'list all available scripts',
'help' => 'shows help');
....
elseif (in_array($option, $availableOptions)) {
echo "- " . greenString($option) . " - " . $availableOptions[$option];
echo "- " . greenString("SYNTAX: ") . $optionsSyntaxes[$option];
echo greenString("-------------------------------\n\n");
}
但出于某种原因,无论我投入什么,它都会评估为假。所以我在交互式shell中尝试了它,当我不运行该函数并运行var_dump($ availableOptions)时,它运行正常。当我添加该功能然后尝试它,即使我手动重新启动它也会失败。这真的很奇怪。
php > help();
PHP Fatal error: Call to undefined function greenString() in php shell code on line 9
php > var_dump($availableOptions);
PHP Notice: Undefined variable: availableOptions in php shell code on line 1
NULL
php > $availableOptions = array( 'run' => 'runs a script', 'list' => 'list all available scripts', 'help' => 'shows help');
php > var_dump($availableOptions);
PHP Notice: Undefined variable: availableOptions in php shell code on line 1
NULL
在运行之前:
php > var_dump($availableOptions);
array(3) {
["run"]=>
string(13) "runs a script"
["list"]=>
string(26) "list all available scripts"
["help"]=>
string(10) "shows help"
}
php >