Skip to content

Stdlib: error_reporting()/trigger_error() — enum case operands must TypeError (ext/standard/basic_functions.c) #9086

Closed

Description

@PurHur

Category

stdlib — php-src-strict enum operand guards

Problem

Enum case objects passed to error-level/message builtins are coerced (backing int/string) instead of throwing TypeError like Zend.

php-src reference

  • ext/standard/basic_functions.c — PHP_FUNCTION(error_reporting), PHP_FUNCTION(trigger_error) / user_error
  • Enum objects are not valid ?int or string operands

Repro

<?php
enum L: int { case ALL = E_ALL; }
enum M: string { case MSG = 'user warning'; }

try { error_reporting(L::ALL); } catch (Throwable $e) { echo 'error_reporting: ', get_class($e), ': ', $e->getMessage(), "\n"; }
try { trigger_error(M::MSG, E_USER_WARNING); } catch (Throwable $e) { echo 'trigger_error: ', get_class($e), ': ', $e->getMessage(), "\n"; }
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Call Zend PHP 8.3+ This compiler VM
error_reporting(L::ALL) TypeError (?int expected) accepts, sets level
trigger_error(M::MSG, …) TypeError (string expected) emits PHP Warning: user warning

Scope (PHP-in-PHP)

Layer Path
VM ext/standard/error_reporting.php, trigger_error.php, user_error.php
JIT matching lowering if present
Tests test/compliance/cases/stdlib/error_builtin_enum_operand.phpt

Done when

  • Both repro calls throw TypeError on VM (php-src-strict)
  • user_error() shares the same message-operand guard
  • Targeted compliance green

Related

Activity

  1. added
    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 Jun 16, 2026
  2. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: repro is already green on master (VM+JIT). Compliance tests exist: error_reporting_enum_typeerror*.phpt (#5917), trigger_error_enum_case*.phpt (#6184), user_error_enum_case.phpt (#6183). Switching to #9084 (sleep/usleep/time_nanosleep enum guards).

  4. PurHur commented on Jul 12, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run (trigger_error enum error_level TypeError gap; #9086)

  5. PurHur commented on Jul 12, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #18272.

    Root cause: trigger_error() VM path used a manual TYPE_INTEGER check that threw LogicException; JIT used raw jitLong() without enum guards. Message-operand enum rejection was already fixed (#6184); error_level enum operand was the remaining gap.

    Fix: Route error_level through VmMath::parseIntBuiltinArgForFrame() (VM) and JitIntdiv::lowerIntBuiltinArgForCaller() (JIT).

    Verification:

    php bin/vm.php test/repro/maintainer_gap_trigger_error_enum_error_level.php
    # trigger_error(): Argument #2 ($error_level) must be of type int, E given
    
    php bin/jit.php test/repro/maintainer_gap_trigger_error_enum_error_level.php
    # trigger_error(): Argument #2 ($error_level) must be of type int, E given
    
    php bin/vm.php test/compliance/cases/stdlib/trigger_error_enum_error_level.phpt
    php bin/jit.php test/compliance/cases/stdlib/trigger_error_enum_error_level_jit.phpt
    
    make bootstrap-selfhost-vm-driver-execute-probe
    # OK
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 machineimplementation-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