Repository navigation
Runtime: CLI / + ['argv'] (register_argc_argv) parity #4374
Copy link
Copy link
Closed
Labels
MOST IMPORTANTThis are the most important targetsThis are the most important targetsarea:vmVirtual machineVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-1:web-runtimePhase 1 – CGI/web runtimePhase 1 – CGI/web runtime
Description
Category
runtime
Problem
In CLI mode, Zend PHP populates $argc, $argv, and $_SERVER['argc']/$_SERVER['argv'] based on process arguments, gated by register_argc_argv (and with predictable shapes/types). PurHur/php-compiler should match Zend behavior, including when scripts are invoked with additional args and when register_argc_argv=0.
Verified gap (2026-06-03): even for bare -r snippets, $argv[0] differs (Standard input code vs Command line code). Multi-arg script invocations are not wired to real CLI args today.
php-src reference
- php/php-src
sapi/cli/php_cli.c— argument vector construction - php/php-src
main/php_variables.c—$argc/$argvand$_SERVERregistration - php/php-src
main/main.c—register_argc_argvINI
Repro (failure today)
repro.php:
<?php
var_dump($argc, $argv);
var_dump($_SERVER['argc'] ?? null, $_SERVER['argv'] ?? null);./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
# Zend reference
php repro.php extra1 extra2
# This compiler (today)
php bin/vm.php repro.php extra1 extra2
# Also compare bare -r:
php -r "var_dump(\$argc, \$argv);"
php bin/vm.php -r "var_dump(\$argc, \$argv);"
'Observed on master (Docker php-compiler:22.04-dev, 2026-06-03):
| Check | Zend PHP 8.2 | bin/vm.php |
|---|---|---|
php -r 'var_dump($argc,$argv);' |
$argc=int(1), $argv[0]="Standard input code" |
same shape but $argv[0]="Command line code" |
$_SERVER['argc'] in -r |
present, mirrors $argc |
present, mirrors $argc |
php repro.php a b |
$argc=3, argv includes script + a + b |
(worker: verify; often still 1-arg stub) |
Second variant (after #4515 / VmIni exposes register_argc_argv):
php -d register_argc_argv=0 repro.php a
php bin/vm.php -d register_argc_argv=0 repro.php a
# Expect: no $argc/$argv (or empty per Zend SAPI rules)Scope (this repo)
- CLI entrypoints:
bin/vm.php,src/cli_driver.php,phpc run - VM globals / superglobals:
lib/VM.php,lib/Web/CGI path if shared - INI:
register_argc_argvvia Stdlib: ini_set()/ini_get() — register_argc_argv + zend.assertions parity (ext/standard, unblocks #4374) #4515
Done when
-
php bin/vm.php repro.php a bmatches Zend:$argc === 3,$argv[0]is script path/basename,$argv[1]==='a',$argv[2]==='b' -
$_SERVER['argv']mirrors$argvwhenregister_argc_argv=1 -
register_argc_argv=0behavior matches Zend (no spurious argv pollution) - Compliance:
test/compliance/cases/runtime/argv_cli.phpt
Links
- INI plumbing: Stdlib: ini_set()/ini_get() — register_argc_argv + zend.assertions parity (ext/standard, unblocks #4374) #4515
- North star: Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492
Implementation notes (2026-06-03 backlog pass)
Committed repro
Add test/repro-maintainer/cli_argv_parity.php:
<?php
var_dump($argc, $argv);
var_dump($_SERVER['argc'] ?? null, $_SERVER['argv'] ?? null);Native / AOT floor
lib/AOT/runtime/phpc_cli_argv.c—__compiler_cli_store_argv; must receive realargc/argvfrombin/vm.php/phpc run/ compiled drivers (Self-host M3: Native emit for compiler compile-smoke fixture (post-#1493) #1937, Self-host M5: bin/compile.php AOT sidecar segfault — missing .m3_bin_compile_aot_blob at emit-helper link #2697)bin/vm.php—--script-argv/ driver wiring today does not forwardextra1 extra2like Zend
Verification matrix
| Command | $argc |
$argv[1] |
|---|---|---|
php test/repro-maintainer/cli_argv_parity.php a b |
3 | a |
php bin/vm.php test/repro-maintainer/cli_argv_parity.php a b |
3 | a |
php bin/jit.php test/repro-maintainer/cli_argv_parity.php a b |
3 | a |
register_argc_argv=0 (see #4515) |
Zend rules | same |
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter cli_argv'
make bootstrap-selfhost-linkDone when (addendum)
-
-rsnippet usesStandard input codefor$argv[0](match Zend 8.2), notCommand line code - AOT-linked
bin-compile-aotinherits forwarded argv for inventory driver
Metadata
Metadata
Assignees
Labels
MOST IMPORTANTThis are the most important targetsThis are the most important targetsarea:vmVirtual machineVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-1:web-runtimePhase 1 – CGI/web runtimePhase 1 – CGI/web runtime
Activity
PurHur commentedon Jun 2, 2026
More concrete parity targets + references:
php-src reference (more specific)
sapi/cli/php_cli.c:do_cli()/ argv parsing andphp_build_argv()hookupmain/php_variables.c:php_register_variable_ex()paths for$_SERVERpopulationregister_argc_argvinphp.ini-development(behavior toggle)php-src tests to mirror
sapi/cli/tests/argv_001.phptsapi/cli/tests/argv_002.phptsapi/cli/tests/register_argc_argv_*.phptExtra edge cases to include
Done-when extension
$argvis an array with sequential integer keys starting at 0.$_SERVER['argv']matches$argvwhen enabled.$argc/$argvare unset or match Zend’s exact disabled behavior for this SAPI.PurHur commentedon Jun 2, 2026
claim: lane-c-worker — starting this run
PurHur commentedon Jun 4, 2026
Implementation-ready addendum (2026-06-04 parity probe)
Verified
$argvwiring gap remains on master. Minimal repro:Expected Zend:
$argv[0]isCommand line codefor-rsnippets; additional CLI args after--appear in$argv.Done-when checklist for workers:
$argc/$argvwithout host PHP delegation$_SERVER['argc']/$_SERVER['argv']mirror$argc/$argvwhenregister_argc_argv=1register_argc_argv=0hides$argc/$argvlike Zendphpc_cli_argv.c)php-src:
sapi/cli/php_cli.c,main/php_variables.cPurHur commentedon Jun 4, 2026
claim: cursor-agent-lane-c — continuing #4374 (Standard input code + -- separator); PR incoming.
Fix CLI -r $argv[0] and -- separator parity with Zend (#4374). (#5880)
PurHur commentedon Jun 4, 2026
Merged #5880
Verification:
php bin/vm.php -rnow matches Zend 8.2 (Standard input code,--stripped before user args); script invocation with extra args unchanged;vendor/bin/phpunit test/compliance/ --filter cli_argvOK.Follow-up:
register_argc_argv=0still blocked on-dINI forwarding (#4515).