Skip to content

Stdlib: wordwrap() width accepts float truncation and numeric strings (#4212) - #8468

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-wordwrap-width-coerce-4212
Jun 14, 2026
Merged

Stdlib: wordwrap() width accepts float truncation and numeric strings (#4212)#8468
PurHur merged 1 commit into
masterfrom
agent/stdlib-wordwrap-width-coerce-4212

Conversation

@PurHur

@PurHur PurHur commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • wordwrap() argument Php stdlib specs implementation #2 ($width) now uses VmMath::parseIntBuiltinArg / JitIntdiv::lowerIntBuiltinArg (php-src ext/standard/string.c Z_PARAM_LONG) instead of rejecting non-int operands with LogicException.
  • JIT compile-time constant folding in JitWordwrap handles float and numeric-string widths.
  • Adds compliance PHPT (VM + JIT), AOT fixture, and maintainer repro.

Closes #4212

php-src reference

  • ext/standard/string.cPHP_FUNCTION(wordwrap) / php_wordwrap

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/wordwrap_width_coerce.php
php bin/vm.php test/repro-maintainer/wordwrap_width_coerce.php
php bin/jit.php test/repro-maintainer/wordwrap_width_coerce.php
php bin/compile.php -l test/repro-maintainer/wordwrap_width_coerce.php
vendor/bin/phpunit --filter wordwrap_width
vendor/bin/phpunit --filter wordwrap_width_coerce test/aot/AotTest.php
'

Output (all three runtimes match Zend):

hello
hello
world
hello
world
TypeError: wordwrap(): Argument #2 ($width) must be of type int, string given
TypeError: wordwrap(): Argument #2 ($width) must be of type int, array given

PHPUnit: OK (5 tests, 9 assertions) for --filter wordwrap_width; AOT fixture OK (1 test, 5 assertions).

Made with Cursor

Use VmMath::parseIntBuiltinArg and JitIntdiv::lowerIntBuiltinArg so float
truncation and numeric-string widths work on VM, JIT, and AOT; add compliance
and AOT fixtures guarding the regression.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 7476978 into master Jun 14, 2026
@PurHur
PurHur deleted the agent/stdlib-wordwrap-width-coerce-4212 branch June 14, 2026 02:21
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: wordwrap() — width must accept floats and numeric strings (ext/standard/string.c parity)

1 participant