Skip to content

Stdlib: number_format() — optional 5th RoundingMode parameter missing (PHP 8.4, ext/standard/number_format.c) #9438

Description

@PurHur

Category

stdlib — php-src-strict PHP 8.4 rounding mode on number_format()

Problem

PHP 8.4 adds an optional 5th $rounding_mode argument (RoundingMode|int) to number_format(). This compiler registers the RoundingMode enum for round() (#5934) but number_format() still rejects any 5th argument with LogicException: number_format() requires one to four arguments.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r '"'"'var_dump(number_format(1.55, 1, ".", "", RoundingMode::HalfAwayFromZero));'"'"''

Zend (PHP 8.4+):

string(3) "2.0"   # example — exact string per mode

This compiler (bin/vm.php):

LogicException: number_format() requires one to four arguments

Contrast: round(2.5, 0, RoundingMode::HalfAwayFromZero) already works on VM.

Scope (PHP-in-PHP)

  • ext/standard/number_format.php — accept argc 5; delegate mode resolution to VmRoundMode / RoundingMode enum
  • ext/standard/VmNumberFormat.php — apply rounding mode in formatting path
  • ext/standard/JitNumberFormat.php — JIT/AOT 5-arg lowering (reuse JitRoundModeResolve / RoundingModeJit)
  • Reuse ext/standard/VmRoundMode.php SSOT; do not duplicate mode tables in LLVM

Done when (php-src-strict)

  • Repro matches Zend output for HalfAwayFromZero, HalfEven, and legacy int mode passthrough.
  • Invalid mode operands TypeError/ValueError like Zend.
  • Compliance guards test/compliance/cases/stdlib/number_format_rounding_mode.phpt (+ JIT variant) green.
  • script/capability-matrix.php notes 5-arg number_format when matrix regen runs.

Related

#5934 (round() + RoundingMode), #8795 (enum operand coercion on number_format args).

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions