Skip to content

Stdlib: str_repeat() — multiplier must accept numeric strings and floats (ext/standard/string.c parity) #4171

Description

@PurHur

Category

stdlib

Problem

Zend coerces str_repeat() argument #2 ($times) from float or numeric string to int. Negative values throw ValueError. This compiler requires a native integer type and throws LogicException before Zend-compatible coercion runs.

php-src reference

Repro

<?php
echo str_repeat('x', 2.9) . "\n"; // Zend: xx
try {
    str_repeat('x', -1);
} catch (ValueError $e) {
    echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
./script/docker-exec.sh -- bash -lc '
  source script/php-env.sh
  php test/repro-maintainer/str_repeat_numeric_multiplier.php
  php bin/vm.php test/repro-maintainer/str_repeat_numeric_multiplier.php
'
Mode 2.9 -1
Zend xx ValueError
VM today LogicException ValueError (OK) but float path blocked

Scope

Area Files
VM ext/standard/str_repeat.php, ext/standard/VmString.php
JIT/AOT ext/standard/str_repeat.php, ext/standard/JitStrRepeat.php
Tests test/compliance/cases/stdlib/str_repeat_numeric_multiplier.phpt

Done when

  • Float/numeric-string $times coerces to int on VM, JIT, and AOT
  • Negative $times still throws ValueError with Zend message family
  • Existing str_repeat PHPTs still pass

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