Skip to content

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

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

henderkes wants to merge 13 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 Outdated

@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.

@henderkes

Copy link
Copy Markdown
Contributor Author

@shivammathur @alexandre-daubois what do you think, pass argv as utf-8 or always as wchar_t and always do the encoding like before?

@shivammathur

shivammathur commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

@henderkes

Thinking more about this, I think we can preserve argv and document the caller’s encoding responsibility. That’s simpler and avoids misinterpreting UTF-8 -d values when PHP uses Windows-1252 for example.

@henderkes

Copy link
Copy Markdown
Contributor Author

I don't think that's a good idea, because the embedding program may not know php's internal encoding.

@shivammathur

Copy link
Copy Markdown
Member

Yes, unless the embedder explicitly sets it.
If we go with UTF-8, we should handle cases like -d auto_prepend_file=café.php when default_charset=Windows-1252. Currently, that value is applied before conversion, so PHP looks for the wrong filename.

@henderkes

Copy link
Copy Markdown
Contributor Author

Yes, unless the embedder explicitly sets it. If we go with UTF-8, we should handle cases like -d auto_prepend_file=café.php when default_charset=Windows-1252. Currently, that value is applied before conversion, so PHP looks for the wrong filename.

But cli never takes the UTF-8 path, it's still going into the argv == __argv branch and converts from wstring to string.

Comment thread sapi/cli/php_cli.c Outdated
@henderkes
henderkes requested a review from bukka as a code owner October 6, 2026 13:14
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