Skip to content

Language: enum case instanceof UnitEnum/BackedEnum false — must match Zend (Zend/zend_operators.c) #9335

Description

@PurHur

Category

language | php-src-strict

Problem

The instanceof operator on enum case operands returns false for UnitEnum and BackedEnum on VM/JIT. Zend treats backed/unit enum cases as objects implementing those interfaces, so instanceof is true.

This is distinct from #9152 (is_a/is_subclass_of function parity) — the opcode path in lib/VM.php / lib/JIT/ must tag enum-case Variable operands with enum interfaces before interface checks.

php-src reference

Repro

<?php
enum E: int { case A = 1; }
var_dump(E::A instanceof UnitEnum);
var_dump(E::A instanceof BackedEnum);
var_dump(E::A instanceof E);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Check Zend PHP 8.x This compiler (bin/vm.php)
E::A instanceof UnitEnum true false
E::A instanceof BackedEnum true false
E::A instanceof E true (verify; may also be wrong if case is scalarized)

Scope

Module Path
VM compare / instanceof lib/VM.php, lib/VM/Variable.php — preserve TYPE_ENUM_CASE through operand resolution
JIT instanceof lib/JIT/IssetHelper.php / instanceof lowering helpers — enum-case interface bitmap
Tests test/compliance/cases/language/enum_instanceof_unitenum.phpt (VM + JIT)

PHP-in-PHP: no new runtime/*.c — enum case representation stays in lib/VM/EnumCaseSupport.php.

Done when

  • Repro matches Zend on VM (bin/vm.php)
  • JIT/AOT agree when --filter enum_instanceof / matching JIT PHPT is in scope
  • ./script/ci-fast.sh --filter enum_instanceof green
  • No regression on scalar instanceof checks

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