Skip to content

Stdlib: str_shuffle() — TypeError for non-string operands (ext/standard/string.c parity) #4551

Description

@PurHur

Category

stdlib

Problem

str_shuffle() must accept only string operands. Zend raises TypeError when argument #1 is not a string (e.g. []). This compiler silently accepts non-string values on VM (no exception) and uses LogicException in the builtin guard instead of TypeError.

Affected: VM (ext/standard/str_shuffle.php), JIT (JitStrShuffle via jitString()).

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "try { str_shuffle([]); echo \"no throw\n\"; } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\\n\"; }"
php bin/vm.php -r "try { str_shuffle([]); echo \"no throw\n\"; } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\\n\"; }"
'
Runtime Behavior
Zend PHP 8.x TypeError: str_shuffle(): Argument #1 ($string) must be of type string, array given
bin/vm.php prints no throw (accepts [] without exception)

Scope (this repo)

Module Path
VM ext/standard/str_shuffle.php
JIT ext/standard/JitStrShuffle.php
Tests test/compliance/cases/stdlib/str_shuffle_type_error.phpt

Done when

  • Non-string argument Php stdlib specs implementation #1 raises TypeError with Zend-like message on VM, JIT, and AOT.
  • Valid string input behavior unchanged (returns permuted string of same byte length).
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/compliance/cases/stdlib/str_shuffle_type_error.phpt' exits 0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions