Skip to content

Stdlib: round() PHP_ROUND_HALF_* named constant mode rejected — TypeError null given (ext/standard/math.c) #9564

Description

@PurHur

Category

stdlib · php-src-strict

Problem

round() third argument cannot accept PHP_ROUND_HALF_* named constants at runtime—the VM passes null and throws:

TypeError: round(): Argument #3 ($mode) must be of type RoundingMode|int, null given
Call Zend VM today
round(2.5, 0, PHP_ROUND_HALF_UP) 3.0 TypeError
round(2.5, 0, PHP_ROUND_HALF_DOWN) 2.0 TypeError
round(3.5, 0, PHP_ROUND_HALF_EVEN) 4.0 TypeError

Same class of bug as #9278 / #9429 (inline SORT_* flags)—builtin arg lowering does not resolve core PHP constants to integers.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_round_php_round_half.php'
php bin/vm.php test/repro/maintainer_gap_round_php_round_half.php

Implementation hints (PHP-in-PHP)

  • ext/standard/round.php + shared constant folding for builtin int args (same helper path as sort flags)
  • ext/standard/JitRound.php if JIT lowers mode separately
  • PHP 8.4+ RoundingMode enum cases should also work when passed by name

Done when

  • Repro script matches Zend
  • round(2.5, 0, PHP_ROUND_HALF_UP) → 3.0 under VM
  • Compliance guard added
  • JIT/AOT round mode agrees

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions