Skip to content

Fix base_convert() enum case operands — TypeError parity (#8976) - #9004

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-8976-base-convert-enum-typeerror
Jun 16, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-8976-base-convert-enum-typeerror

Conversation

@PurHur

@PurHur PurHur commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Route base_convert() $num through VmString::coerceStringBuiltinArg (VM) and JitStringBuiltinArg::lower (JIT/AOT) so backed enum cases throw TypeError like Zend Z_PARAM_STR, instead of LogicException or silent backing coercion.
  • php-src reference: ext/standard/string.c — PHP_FUNCTION(base_convert)

Verification

# Issue repro — VM matches Zend TypeError
php test/repro-maintainer/parity_base_convert_enum.php
php bin/vm.php test/repro-maintainer/parity_base_convert_enum.php
# TypeError: base_convert(): Argument #1 ($num) must be of type string, Es given

# Scalar unchanged
php bin/vm.php -r 'echo base_convert("ff", 16, 10), "\n";'
# 255

# JIT
php bin/jit.php -r 'enum Es: string { case A = "ff"; } try { base_convert(Es::A,16,10); } catch (TypeError $e) { echo $e->getMessage(), "\n"; }'
# base_convert(): Argument #1 ($num) must be of type string, Es given

# Compliance (Docker)
./script/docker-exec.sh -- bash -lc 'php vendor/bin/phpunit test/compliance/VMTest.php --filter base_convert_enum_typeerror'
# OK (2 tests)

# AOT compile-only
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/compile.php -l test/fixtures/aot/compile-only/base_convert_enum_typeerror.php'
# exit 0

php vendor/bin/phpunit test/unit/AotRegressionFixtureCatalogTest.php --filter base_convert_enum
# OK (1 test)

Closes #8976

Made with Cursor

…8976).

Route $num through VmString::coerceStringBuiltinArg and JitStringBuiltinArg
like hexdec/octdec so backed enum cases match Zend Z_PARAM_STR rejection.

Co-authored-by: Cursor <cursoragent@cursor.com>
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: base_convert() — enum case $num operand must TypeError (ext/standard/string.c, php-src-strict)

1 participant