use*_*942 2 php symfony laravel laravel-artisan
我经营工匠:
php artisan down --message "Going down for maintenance" --retry=60
Run Code Online (Sandbox Code Playgroud)
[更新] 或者像@Remul 建议的那样运行它:
php artisan down --message="Going down for maintenance" --retry=60
Run Code Online (Sandbox Code Playgroud)
然后两者都给了我错误:
[Symfony\Component\Console\Exception\RuntimeException]
Too many arguments, expected arguments "command".
Run Code Online (Sandbox Code Playgroud)
如果像这样运行没有空格的命令:
php artisan down --message "Going_down_for_maintenance" --retry=60
Run Code Online (Sandbox Code Playgroud)
没有错误发生
我正在使用 php 7.0.14
我想通了:
问题实际上是 php 如何从命令行获取参数在 vendor/symfony/console/Input/ArgvInput.php 我可以理解 php 获取这样的参数:
0 => "artisan"
1 => "down"
2 => "--message=Going"
3 => "down"
4 => "for"
5 => "maintenance"
6 => "--retry=60"
Run Code Online (Sandbox Code Playgroud)
因此,为了确保我使用以下内容制作了自己的脚本:
<?php
var_dump($argv);
Run Code Online (Sandbox Code Playgroud)
我运行它:
php -v;php test_argv.php "parm with space" other_parameter
Run Code Online (Sandbox Code Playgroud)
输出是:
PHP 7.0.14 (cli) (built: Jan 30 2017 15:45:33) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
array(5) {
[0]=>
string(13) "test_argv.php"
[1]=>
string(4) "parm"
[2]=>
string(4) "with"
[3]=>
string(5) "space"
[4]=>
string(15) "other_parameter"
}
Run Code Online (Sandbox Code Playgroud)
我在不同版本的 PHP 的其他机器上运行它并查看我的结果:
PHP 7.1.5 (cli) (built: Sep 19 2017 10:48:01) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.4, Copyright (c) 2002-2017, by Derick Rethans
array(3) {
[0] =>
string(13) "test_argv.php"
[1] =>
string(15) "parm with space"
[2] =>
string(15) "other_parameter"
}
Run Code Online (Sandbox Code Playgroud)
看起来在 php 7.0 和 7.1 中 argv 解析是完全不同的,一个忽略双引号作为字符串分隔符,而后者则不