Skip to content

Stdlib: mt_getrandmax() missing while mt_rand()/getrandmax() registered (ext/random/random.c) #17228

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

mt_rand() and legacy getrandmax() are registered, but mt_getrandmax() is absent. Portable code and vendor patches (e.g. php-cfg loop labels) call mt_getrandmax() and fatals.

Repro Zend 8.2 VM (2026-07-07)
function_exists('mt_getrandmax') after mt_rand present true false
mt_getrandmax() 2147483647 Call to undefined function mt_getrandmax()

php-src reference

PHP implementation target

  • ext/standard/mt_getrandmax.php — thin builtin returning 2147483647 (MT_RAND_MAX)
  • ext/standard/Module.php — register beside mt_rand() / getrandmax()
  • JIT: constexpr return or shared helper; AOT via existing random lowering

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_mt_getrandmax_missing.php'
# Zend: ok max=2147483647
# VM:   fail: mt_getrandmax() undefined while mt_rand() exists

Done when

  • mt_getrandmax() registered on VM/JIT/AOT
  • Returns 2147483647; zero-arg ArgumentCountError on excess args
  • Compliance .phpt under test/compliance/cases/stdlib/
  • php-src-strict

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 7, 2026
  2. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run

  3. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run (implementing mt_getrandmax builtin + AOT)

  4. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #17235.

    Verification

    • VM repro test/repro/maintainer_gap_mt_getrandmax_missing.php — mt_getrandmax=yes, returns 2147483647, ArgumentCountError on surplus arg
    • PHPUnit --filter mt_getrandmax — 4/4 (VM + JIT compliance)
    • AOT bin/compile.php -l + native binary run — function registered, returns 2147483647
    • bootstrap-inventory.php --check + spine sync OK

    Implementation: ext/standard/mt_getrandmax.php (constexpr JIT/AOT via VmMt19937::PHP_MT_RAND_MAX), registered beside getrandmax() in Module.php. php-src ref: ext/random/random.c PHP_FUNCTION(mt_getrandmax).

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