Category
stdlib · php-src-strict · spec refresh 2026-06-18
Problem
getopt() is registered (function_exists → true; #3251 / #9065 stale “missing” title). Option parsing works for php bin/vm.php -r '...' (CLI flags after -r script reach getopt), but script-file invocation may still return an empty array when flags follow the script path — unlike Zend SAPI argv layout.
Workers must verify both entry paths; do not close on -r alone.
php-src reference
Repro
Create test/repro/maintainer_getopt_cli.php (referenced in prior spec — not yet committed; implementer should add):
<?php
var_export(getopt('ab:', ['long:', 'opt::']));
echo "\n";
Commands
# Script-file path (primary repro)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_getopt_cli.php -a -b B --long L --opt=V -- -x'
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_getopt_cli.php -a -b B --long L --opt=V -- -x'
# Inline -r path (audit 2026-06-18 — WORKS on VM)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(getopt(\"ab:\", [\"long:\", \"opt::\"])); echo PHP_EOL;" -a -b B'
# Actual: array ( "a" => false, "b" => "B", ) ✅
| Path |
Expected |
VM audit 2026-06-18 |
-r one-liner |
parsed opts |
✅ non-empty |
script.php -a … |
parsed opts |
verify / likely empty ❌ |
Expected Zend shape for full repro:
array ('a' => false, 'b' => 'B', 'long' => 'L', 'opt' => 'V')
Scope (this repo)
| Layer |
Path |
| VM |
ext/standard/getopt.php, ext/standard/GetoptEngine.php |
| Runtime |
cliRequestArgv population in VM context / bin/vm.php driver — must mirror SAPI argv after script name |
| JIT |
lib/JIT/Builtin/GetoptJitHelper.php — same argv snapshot |
| Tests |
test/compliance/cases/stdlib/getopt_cli.phpt |
Done when
Supersedes stale audit in #9065 (function exists; behavior gap). Ref: #1492, #3251
Category
stdlib· php-src-strict · spec refresh 2026-06-18Problem
getopt()is registered (function_exists→ true; #3251 / #9065 stale “missing” title). Option parsing works forphp bin/vm.php -r '...'(CLI flags after-rscript reachgetopt), but script-file invocation may still return an empty array when flags follow the script path — unlike Zend SAPIargvlayout.Workers must verify both entry paths; do not close on
-ralone.php-src reference
ext/standard/php_getopt.cext/standard/basic_functions.c—PHP_FUNCTION(getopt)usesPG(argv)main/php.h— argv layout after script nameRepro
Create
test/repro/maintainer_getopt_cli.php(referenced in prior spec — not yet committed; implementer should add):Commands
-rone-linerscript.php -a …Expected Zend shape for full repro:
Scope (this repo)
ext/standard/getopt.php,ext/standard/GetoptEngine.phpcliRequestArgvpopulation in VM context /bin/vm.phpdriver — must mirror SAPI argv after script namelib/JIT/Builtin/GetoptJitHelper.php— same argv snapshottest/compliance/cases/stdlib/getopt_cli.phptDone when
::, and--terminator-rpath remains green (regression guard)rest_indexby-ref third parameter works on VM (Stdlib: getopt() — CLI short/long option parsing (ext/standard/getopt.c parity) #3251 phase 1)./script/ci-fast.sh --filter getopt_cligreenSupersedes stale audit in #9065 (function exists; behavior gap). Ref: #1492, #3251