Skip to content

Stdlib: round() mode: named arg skips omitted precision (#9564) - #16946

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-9564-round-half-constants
Jul 6, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-9564-round-half-constants

Conversation

@PurHur

@PurHur PurHur commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix round($num, mode: PHP_ROUND_HALF_*) when $precision is omitted: sparse named-arg maps bind mode at index 2, but count($calledArgs)===2 wrongly treated index 1 as precision.
  • Use isset($frame->calledArgs[n]) per slot in VM round.php (same pattern as number_format.php) and NamedOptionalCallArgs::isOmittedOptional() in JitRound.php.
  • Add maintainer repro + extend round_named_params.phpt with mode:-only case.

Closes #9564

Root cause

round.php used $argc >= 2 / $argc === 3 on a sparse named-arg array ([0 => num, 2 => mode]). count() is 2, so precision was read from the missing/wrong slot.

php-src reference

ext/standard/math.c — zif_round accepts optional precision + mode independently.

Verification

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

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/repro/maintainer_gap_round_php_round_half.php'
# 3 / 2 / 4 / 3

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "echo round(2.5, mode: PHP_ROUND_HALF_UP), \"\\n\";"'
# 3

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter round_named_params'
# OK (VM + JIT compliance)

Note: AOT round_precision_mode fixture was already red on master (unrelated LLVM round lowering); VM/JIT paths fixed here.

Made with Cursor

Sparse named-arg maps place mode at index 2 while precision is unset;
use isset() per parameter slot instead of argc>=2 / argc===3.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit bb656dd into master Jul 6, 2026
@PurHur
PurHur deleted the agent/issue-9564-round-half-constants branch July 6, 2026 14:45
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: round() PHP_ROUND_HALF_* named constant mode rejected — TypeError null given (ext/standard/math.c)

1 participant