Skip to content

Regression: clamp() callable on ≤8.5 profiles — PHP 8.6-only API leaks (ext/standard/math.c, re-gate CompilerVersion) #21022

Description

@PurHur

Category

stdlib · php-src-strict · profile gate / phantom API

Problem

clamp() landed in php-src 8.6 (RFC clamp_v2, PR #19434). This repo already implements it (ext/standard/clamp.php, VmMath::clamp, JitClamp) but gates are wrong vs Zend:

  • Comments / supportsClamp() treat it as PHP 8.3+
  • Under PHP_COMPILER_PROFILE=8.4: function_exists('clamp') is false, yet clamp(5,1,3) returns 3 (callable via supportsClamp while advertisesClamp hides it)
  • Under PROFILE=8.3: function_exists is true and call works — Zend 8.3 has no clamp
  • Under PROFILE=8.6: still not advertised/aligned with Zend 8.6

Verified 2026-07-19 on master (VERSION=8.4.0-dev):

Profile function_exists('clamp') clamp(5,1,3) Zend
8.3 true 3 undefined function
8.4 false 3 (still callable!) undefined function
8.6 false (callable if supports) 3 + exists true

php-src reference

PHP implementation target

  • Retarget CompilerVersion::supportsClamp() / advertisesClamp() to language profile ≥ 8.6 (both register and function_exists)
  • Keep PHP implementation; fix docs that say “PHP 8.3”
  • On ≤8.5 profiles: undefined-function Error like Zend (no silent call path)
  • No new C

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/clamp_gate.php << "PHP"
<?php
echo "exists=", function_exists("clamp") ? "1" : "0", "\n";
try {
  echo "call=", clamp(5, 1, 3), "\n";
} catch (Throwable $e) {
  echo get_class($e), ": ", $e->getMessage(), "\n";
}
PHP
for p in 8.3 8.4 8.6; do
  echo "=== PROFILE=$p ==="
  PHP_COMPILER_PROFILE=$p php bin/vm.php /tmp/clamp_gate.php
done'

Done when

  • PROFILE≤8.5: function_exists false and call throws undefined-function Error (php-src-strict)
  • PROFILE=8.6 (or ≥8.6): function_exists true; clamp(5,1,3)===3; ValueError on min>max / NAN bounds like Zend
  • Compliance .phpt for both phantom and forward profiles; php-src-strict

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-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