Category
stdlib
Problem
CLI tools and bootstrap scripts parse argv with getopt(). Compiled CLI binaries and self-host probes need getopt() in the VM stdlib for Zend parity.
Duplicate: #4473 tracks the same builtin with extended repro (optional-arg ::, repeated long opts). Claim only one of #3251 / #4473 per worker run; close the other when green.
php-src reference
ext/standard/php_getopt.c — php_getopt(), PHP_FUNCTION(getopt)
ext/standard/php_getopt.h
- Tests:
ext/standard/tests/general_functions/getopt*.phpt
Repro (failure today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_export(function_exists(\"getopt\"));"'
| Runtime |
function_exists('getopt') |
| Zend PHP 8.x |
true |
bin/vm.php |
false |
Full behavioral repro (save repro_getopt.php):
<?php
$argv = ['tool.php', '-a', '-b', 'BVAL', '--help', '--output=out.txt', '--output', 'out2.txt'];
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = count($argv);
var_export(getopt('ab:', ['help', 'output:']));
echo "\n";
Zend returns:
array (
'a' => false,
'b' => 'BVAL',
'help' => false,
'output' => array (0 => 'out.txt', 1 => 'out2.txt'),
)
Scope (this repo)
| Layer |
Files |
Notes |
| VM |
ext/standard/getopt.php (new) |
Read $argv from VM superglobal / $_SERVER['argv'] |
| Parser |
Port subset of php_getopt() from php-src or wrap libc getopt_long where harness-safe |
|
| Register |
ext/standard/Module.php |
|
| v1 |
Short abc: / abc::, long ["foo", "bar:"] |
Match php-src arity rules |
| Tests |
test/compliance/cases/stdlib/getopt.phpt |
|
| JIT/AOT |
v1 VM-only acceptable |
Document in matrix |
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter getopt'
Links
Category
stdlibProblem
CLI tools and bootstrap scripts parse argv with
getopt(). Compiled CLI binaries and self-host probes needgetopt()in the VM stdlib for Zend parity.Duplicate: #4473 tracks the same builtin with extended repro (optional-arg
::, repeated long opts). Claim only one of #3251 / #4473 per worker run; close the other when green.php-src reference
ext/standard/php_getopt.c—php_getopt(),PHP_FUNCTION(getopt)ext/standard/php_getopt.hext/standard/tests/general_functions/getopt*.phptRepro (failure today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_export(function_exists(\"getopt\"));"'function_exists('getopt')truebin/vm.phpfalseFull behavioral repro (save
repro_getopt.php):Zend returns:
Scope (this repo)
ext/standard/getopt.php(new)$argvfrom VM superglobal /$_SERVER['argv']php_getopt()from php-src or wrap libcgetopt_longwhere harness-safeext/standard/Module.phpabc:/abc::, long["foo", "bar:"]test/compliance/cases/stdlib/getopt.phptDone when
function_exists('getopt')istrueon VMvar_exportmatches Zend (including repeated--output)false+E_WARNINGlike Zend (spot-check)./script/ci-fast.sh --filter getoptgreenscript/capability-matrix.phpVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter getopt'Links
php_sapi_name())