Skip to content

Stdlib: number_format() — numeric string coercion (ext/standard/number_format.c parity) #3596

Description

@PurHur

Summary

number_format() rejects numeric strings for argument #1 ("1234.5"), while Zend coerces numeric strings to float/int before formatting. This breaks common web/form code paths.

Related but distinct from #3549 (internal strpos/strlen rules).

php-src reference

Repro

<?php
echo number_format("1234.567", 2), "\n"; // Zend: 1,234.57

This compiler (VM):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "echo number_format(\"1234.5\", 2), \"\\n\";"'
# LogicException: number_format() number must be an integer or float in this compiler build

Current guard: ext/standard/number_format.php lines 37–38 (strict int/float only).

Expected

  • Accept int, float, and numeric strings (including "1234.5", "1e3").
  • Reject non-numeric strings with TypeError (PHP 8+) or Warning+0 per Zend for invalid input.
  • JIT/AOT: same coercion in JitNumberFormat::format().

Scope

  • VM + JIT + AOT.
  • Compliance: test/compliance/cases/stdlib/number_format_numeric_string.phpt.

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