Skip to content

Stdlib: getopt() CLI option parsing (#3251) - #7978

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3251-getopt
Jun 11, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-3251-getopt

Conversation

@PurHur

@PurHur PurHur commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement getopt() in PHP (ext/standard/GetoptEngine.php + getopt.php) parsing SAPI argv snapshot (Context::$cliRequestArgv) for Zend parity with ext/standard/php_getopt.c.
  • Register builtin in ext/standard/Module.php; JIT/AOT VM-only v1 (throws LogicException).
  • Add compliance .phpt, GetoptVMTest, and test/repro/maintainer-getopt.php.

Closes #3251

php-src reference

  • ext/standard/php_getopt.c / php_getopt.h
  • ext/standard/basic_functions.c — PHP_FUNCTION(getopt)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_export(function_exists(\"getopt\"));"'
# bool(true)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer-getopt.php -a -b BVAL --help --output=out.txt --output out2.txt'
# array (
#   'a' => false,
#   'b' => 'BVAL',
#   'help' => false,
#   'output' => array (0 => 'out.txt', 1 => 'out2.txt'),
# )

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter getopt'
# OK (2 tests)

Made with Cursor

Add PHP-in-PHP getopt via GetoptEngine over SAPI argv snapshot,
matching Zend short/long option shapes for bootstrap CLI scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 49506ac into master Jun 11, 2026
@PurHur
PurHur deleted the agent/issue-3251-getopt branch June 11, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: getopt() — CLI short/long option parsing (ext/standard/getopt.c parity)

1 participant