Skip to content

Stdlib: wordwrap() — width must accept floats and numeric strings (ext/standard/string.c parity) #4212

Description

@PurHur

Category

stdlib

Problem

wordwrap() argument #2 ($width) is parsed as Z_PARAM_LONG in php-src (float truncated, numeric strings accepted). This compiler requires strict integer types and rejects valid Zend calls.

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "echo wordwrap(\"hello\", 1.9), \"\\n\"; echo wordwrap(\"hello\", \"2\"), \"\\n\";"
php bin/vm.php -r "echo wordwrap(\"hello\", 1.9), \"\\n\"; echo wordwrap(\"hello\", \"2\"), \"\\n\";" 2>&1 || true
'
Call Zend PHP 8.2 This compiler
wordwrap('hello', 1.9) hello (width 1) LogicException
wordwrap('hello', '2') wrapped at width 2 LogicException

Scope (this repo)

  • ext/standard/wordwrap.php, ext/standard/VmString.php::wordwrap()
  • JIT: ext/standard/JitWordwrap.php — coerce width before __compiler_wordwrap
  • test/compliance/cases/stdlib/wordwrap_width_coerce.phpt

Done when

  • VM/JIT/AOT: repro matches Zend
  • Invalid width ('abc', []) → TypeError/ValueError per Zend
  • ./script/ci-fast.sh --filter wordwrap_width green

Related

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 machineenhancementNew feature or requestimplementation-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