Skip to content

Stdlib: trigonometric/hyperbolic math builtins — enum case operands must TypeError (ext/standard/math.c, phase 2 of #5613) #5883

Description

@PurHur

Category

stdlib · php-src-strict

Problem

Phase 1 umbrella #5613 covers abs/ceil/floor/round/sqrt, but trigonometric, hyperbolic, and two-argument math builtins still accept enum case operands (or fail with non-Zend messages) instead of TypeError like Zend (Z_PARAM_DOUBLE / Z_PARAM_NUMBER).

Verified probe (2026-06-04, php-compiler:22.04-dev):

Builtin Zend VM (today)
sin / cos / tan TypeError succeeds (ok)
asin / acos / atan TypeError succeeds
sinh / cosh / tanh TypeError succeeds
expm1 / log1p TypeError succeeds
deg2rad / rad2deg TypeError succeeds
atan2 / hypot / fmod TypeError … requires exactly two arguments (LogicException)

php-src reference

Repro

test/repro-maintainer/parity_trig_math_enum_type_error.php:

<?php
enum E: int { case A = 1; }
foreach (['sin','cos','deg2rad','fmod'] as $fn) {
    try {
        $fn === 'fmod' ? $fn(E::A, 2.0) : $fn(E::A);
        echo "$fn: ok\n";
    } catch (TypeError $e) {
        echo "$fn: TypeError\n";
    } catch (Throwable $e) {
        echo "$fn: ", get_class($e), "\n";
    }
}
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_trig_math_enum_type_error.php
php bin/vm.php test/repro-maintainer/parity_trig_math_enum_type_error.php'

Scope (PHP-in-PHP)

Layer Files
VM ext/standard/sin.php, cos.php, tan.php, asin.php, acos.php, atan.php, atan2.php, sinh.php, cosh.php, tanh.php, expm1.php, log1p.php, hypot.php, fmod.php, deg2rad.php, rad2deg.php — reject Variable::TYPE_ENUM_CASE before numeric coercion
JIT Matching ext/standard/Jit*.php / lib/JIT/Builtin/ lowerers
Tests test/compliance/cases/stdlib/trig_math_enum_case_type_error.phpt

Done when

  • All listed builtins throw catchable TypeError with Zend-aligned messages on enum case operands (VM)
  • No silent backing-value coercion
  • ./script/ci-fast.sh --filter trig_math_enum_case green

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions