Skip to content

fix(stdlib): str_shuffle() TypeError for non-string operands (#4551) - #7543

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-str-shuffle-typeerror-4551
Jun 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/stdlib-str-shuffle-typeerror-4551

Conversation

@PurHur

@PurHur PurHur commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Wire str_shuffle() through VmString::coerceStringBuiltinArg() (VM) and JitStringBuiltinArg::lower() (JIT/AOT) so non-string argument Php stdlib specs implementation #1 raises TypeError with Zend-like messages, matching php/php-src ext/standard/string.c PHP_FUNCTION(str_shuffle).
  • Replaces silent acceptance of [] and LogicException for wrong types.
  • Adds compliance PHPT (VM + JIT) and AOT lint fixture.

Closes #4551

php-src reference

  • ext/standard/string.c — PHP_FUNCTION(str_shuffle) (Z_PARAM_STR)

Implementation

Path Role
ext/standard/str_shuffle.php VM + JIT lowering via shared string-builtin guards
test/compliance/cases/stdlib/str_shuffle_type_error*.phpt VM/JIT parity
test/fixtures/aot/cases/str_shuffle_type_error.phpt AOT lint fixture

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "try { str_shuffle([]); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\n\"; }"
php bin/vm.php -r "try { str_shuffle([]); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\n\"; }"
php bin/compile.php -l -r "str_shuffle([]);"
vendor/bin/phpunit --filter "VMTest::testCases.*str_shuffle"
'

Output:

TypeError: str_shuffle(): Argument #1 ($string) must be of type string, array given
TypeError: str_shuffle(): Argument #1 ($string) must be of type string, array given
OK (4 tests, 4 assertions)

Note: Full AOT link (bin/compile.php -o) and MCJIT execute for type_error PHPTs share pre-existing LLVM verify failures on this harness (same as crc32_type_error / ucfirst_type_error); AOT lint (-l) and VM paths are green.

Made with Cursor

Use VmString::coerceStringBuiltinArg and JitStringBuiltinArg so array/object
operands match php-src ext/standard/string.c instead of silently accepting
non-strings or throwing LogicException.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 05e3c89 into master Jun 7, 2026
@PurHur
PurHur deleted the agent/stdlib-str-shuffle-typeerror-4551 branch June 7, 2026 18:18
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: str_shuffle() — TypeError for non-string operands (ext/standard/string.c parity)

1 participant