diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index 9502a6726fe4..abf41d510a59 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -55,6 +55,7 @@ typedef struct php_cli_server_context { } php_cli_server_context; /* this performs full cli-SAPI boot, loads modules, sets up TSRM and co. */ +/* On Windows, custom argv must use PHP's internal encoding (UTF-8 by default). */ extern PHP_CLI_API int do_php_cli(int argc, char *argv[]); #endif /* CLI_H */ diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 9cd1f5a8c158..3d21eb046ede 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1333,12 +1333,16 @@ PHP_CLI_API int do_php_cli(int argc, char *argv[]) #if defined(PHP_WIN32) php_win32_cp_cli_setup(); orig_cp = (php_win32_cp_get_orig())->id; - /* Ignore the delivered argv and argc, read from W API. This place - might be too late though, but this is the earliest place ATW - we can access the internal charset information from PHP. */ - argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args); - PHP_WIN32_CP_W_TO_ANY_ARRAY(argv_wide, num_args, argv, argc) - using_wide_argv = 1; + /* Embedders supply their own arguments, we mustn't replace them with + * the ones by the host process command line. */ + if (argv_save == __argv) { + /* Ignore the delivered argv and argc, read from W API. This place + might be too late though, but this is the earliest place ATW + we can access the internal charset information from PHP. */ + argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args); + PHP_WIN32_CP_W_TO_ANY_ARRAY(argv_wide, num_args, argv, argc) + using_wide_argv = 1; + } SetConsoleCtrlHandler(php_cli_win32_ctrl_handler, TRUE); #endif