PHP $argv仅限于Windows上的9个参数吗?

在Win7 32位上的 PHP 5.5.4 CLI中运行以下脚本
PHP -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14

我可以看到实际上只解析了8个参数:

Array
(
    [0] => -
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
)

Windows或PHP是否将命令行参数的数量限制为8 /总计9?

更新:

PHP 5.5.7的同一台PC上按预期工作 – >所以至少在Win7上这是一个特定于PHP的问题.

行为的变化取决于脚本是从PHP文件夹运行还是通过路径找到PHP. procmon跟踪似乎表明问题出在Windows上 – 甚至在加载PHP.exe映像之前 – 传递了不同数量的参数:

PHP.exe Process Start       SUCCESS Parent PID: 9088,Command line: "\Program Files\PHP\PHP"  -r "print_r($argv);" 1 2 3 4 5 6 7,Current directory: C:\
PHP.exe Process Start       SUCCESS Parent PID: 9088,Command line: "\program files\PHP\PHP"  -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14,Command line: PHP  -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14,Current directory: C:\Program Files\PHP\

如果不从路径中获取PHP,则所有参数似乎都可用.

在某些Windows环境中.要在Windows XP上获得9个以上的参数,您需要“移动”批处理文件中的参数.

我在XP上面的版本上找不到对此命令的任何引用,因此可能是因为Windows的更高版本会出现此问题.

关于PHP.NET的评论涵盖了它:http://www.php.net/manual/en/features.commandline.php#56846

To pass more than 9 arguments to your PHP-script on Windows,you can
use the ‘shift’-command in a batch file. After using ‘shift’,%1
becomes %0,%2 becomes %1 and so on – so you can fetch argument 10
etc.

Here’s an example – hopefully ready-to-use – batch file:

foo.bat:

@echo off

:init_arg
set args=

:get_arg
shift
if "%0"=="" goto :finish_arg
set args=%args% %0 goto :get_arg

:finish_arg

set PHP=C:\path\to\PHP.exe
set ini=C:\path\to\PHP.ini
%PHP% -c %ini%
foo.PHP %args%

Usage on commandline: foo -1 -2 -3 -4 -5 -6 -7 -8 -9 -foo -bar

A print_r($argv) will give you all of the passed arguments.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...