Skip to content

Language: (int) cast on enum case must emit E_WARNING like Zend (Zend/zend_enum.c) #9479

Description

@PurHur

Category

language · php-src-strict

Problem

Casting a backed enum case to int with (int) must emit E_WARNING: Object of class E could not be converted to int and still yield the backing value. VM today returns 1 silently (no warning, no error_get_last() entry).

Related coercion gaps: #8974 (settype), #9001 (strval must Error). This issue is specifically the (int) cast operator on enum objects.

php-src reference

Repro

test/repro/maintainer_gap_enum_int_cast_warning.php:

<?php
enum E: int { case A = 1; }
set_error_handler(static fn (): bool => true);
var_export((int) E::A);
echo "\n";
var_export(error_get_last()['message'] ?? 'no warning');
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_enum_int_cast_warning.php
./script/docker-exec.sh -- php test/repro/maintainer_gap_enum_int_cast_warning.php
Engine Value Warning
Zend 1 Object of class E could not be converted to int
VM today 1 no warning

Scope (this repo)

  • lib/VM.php cast handler / TypeCheck — enum branch before silent scalar extraction
  • Shared guards: align with VmString::coerceStringBuiltinArg-style centralization if a cast helper exists
  • JIT: mirror via same PHP helper when (int) on enum is compiled

Done when

  • Repro emits Zend-compatible warning + returns backing int
  • Compliance: test/compliance/cases/language/enum_int_cast_warning.phpt
  • ./script/ci-fast.sh --filter enum_int_cast_warning green
  • No new C runtime logic

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-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions