Skip to content

Stdlib: utf8_decode() scalar coercion + TypeError parity (#4317) - #7964

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4317-utf8-scalar-coercion
Jun 11, 2026
Merged

Stdlib: utf8_decode() scalar coercion + TypeError parity (#4317)#7964
PurHur merged 1 commit into
masterfrom
agent/issue-4317-utf8-scalar-coercion

Conversation

@PurHur

@PurHur PurHur commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • utf8_decode() VM path now uses VmString::coerceStringBuiltinArg() (php-src convert_to_string on arg Php stdlib specs implementation #1) instead of LogicException for non-strings
  • JIT/AOT path uses JitStringBuiltinArg::lower() matching utf8_encode()
  • Align utf8_encode() TypeError param name to $string per php-src stub
  • Add compliance + AOT fixtures; maintainer repro at test/repro-maintainer/utf8_encode_scalar.php

php-src reference: ext/standard/basic_functions.cPHP_FUNCTION(utf8_encode), PHP_FUNCTION(utf8_decode)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/utf8_encode_scalar.php
php bin/vm.php test/repro-maintainer/utf8_encode_scalar.php
php bin/jit.php test/repro-maintainer/utf8_encode_scalar.php
'

Output:

'65'
'195'
encode TypeError
decode TypeError
(same on VM and JIT)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter utf8_encode_decode_scalar'
OK (4 tests, 8 assertions)

Closes #4317

Made with Cursor

utf8_decode() now uses VmString::coerceStringBuiltinArg and JitStringBuiltinArg
like utf8_encode(), matching php-src convert_to_string on argument #1.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit dff7ce2 into master Jun 11, 2026
@PurHur
PurHur deleted the agent/issue-4317-utf8-scalar-coercion branch June 11, 2026 08:14
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: utf8_encode()/utf8_decode() — scalar-to-string coercion (ext/standard/basic_functions.c parity)

1 participant