Skip to content

fix: don't force-overwrite argv if do_php_cli is called by embedder - #23891

Open
henderkes wants to merge 3 commits into
php:PHP-8.6from
henderkes:fix/windows-embedded-cli-argv
Open

henderkes wants to merge 3 commits into
php:PHP-8.6from
henderkes:fix/windows-embedded-cli-argv

Conversation

@henderkes

Copy link
Copy Markdown
Contributor

https://learn.microsoft.com/en-us/cpp/c-runtime-library/argc-argv-wargv?view=msvc-170

if we get called by an embedder (argv != __argv) don't re-parse the cmd.

@henderkes

henderkes commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

cc @alexandre-daubois as this concerns frankenphp

cc @shivammathur for windows-specific review I think

Comment thread sapi/cli/php_cli.c
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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller's own argv skips the transcoding to PHP's internal charset that the CommandLineToArgvW() branch performs, so a narrow main() host passing café.php in the ANSI code page hands raw ANSI bytes to the script lookup and to $argv. You may want to document in UPGRADING.INTERNALS that do_php_cli() expects argv in the internal encoding on Windows, or convert from CP_ACP on this branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, fair point. I'm not aware of a safe detection + conversion in winapi, so it might indeed have to be documented.

@shivammathur shivammathur left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test the Windows do_php_cli() argument contract, also I agree with Alexandre that the embedder-supplied narrow argv skips transcoding.

@henderkes

henderkes commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Hmm, small issue in this is also that we're kind of expecting embedders to pass argv in the internal encoding (which is utf-8 by default, but short of explicitly overwriting it, an embedder couldn't be sure). Should we instead require utf-8 and do the conversion if necessary? It's a bit extra code.

Edit: went with always taking utf-8, I don't see another good way of dealing with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants