Commit 5a6116fe34b for php

commit 5a6116fe34b45f04f728a5708bee0be0cc2fd157
Author: Marc <m@pyc.ac>
Date:   Tue Nov 3 17:12:08 2026 +0700

    Fix windows embedded CLI argv overwriting (#24733)

diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h
index 9502a6726fe..abf41d510a5 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 0a6aa82a3be..985ede04b5b 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1335,12 +1335,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