从Windows 10 XAMPP执行PHP CLI脚本时未定义$ argv
I'm attempting to execute a PHP script from the command line in Windows 10 while using XAMPP for localhost.
From the Git terminal application on Windows 10, I'm running the following command:
/c/xampp/php/php.exe /path/to/script/script.php arg1=val1
The script executes correctly, but when I try to do the following:
print_r($argv);
I get the following error:
PHP Notice: Undefined variable: argv in /path/to/script/script.php on line line-#.
Also, php_sapi_name()
returns cli
, so I should be good, but both $argv
and $argc
return as undefined.
Does anyone know why? Thanks.
我正在尝试使用XAMPP for localhost从Windows 10中的命令行执行PHP脚本。 p>
从Windows 10上的Git终端应用程序,我运行以下命令: p>
/c/xampp/php/php.exe /path/to/script/script.php arg1 = val1
code> pre>
脚本正确执行,但是当我尝试执行以下操作时: p>
print_r($ argv);
code> pre>
我收到以下错误: p>
PHP注意:未定义的变量:行中的/path/to/script/script.php中的argv - #。
code> pre>
此外, php_sapi_name() code>返回 cli code>,所以我应该很好,但 $ argv code>和 $ argc code>都返回为undefined。 p> \ n
有谁知道为什么? 谢谢。 p>
div>
As docs say, $argv
and $argc
are not defined unless this feature is explicitly enabled via php.ini
's register_argc_argv, so check your config file first.
But regardless of the check results, I'd rather recommend using $_SERVER['argv']
/ $_SERVER['argc']
instead ($_SERVER
is populated also in CLI), as this is not affected by register_argc_argv
.