Skip to content

Regression: (object) cast on enum case returns empty stdClass not enum identity (re-#9569, Zend/zend_operators.c) #9950

Description

@PurHur

Category

language · php-src-strict · regression

Problem

Closed #9569 fixed (object) cast on enum cases, but VM regressed: (object) E::A yields an empty stdClass ($o === E::A false, $o instanceof E false) instead of returning the same enum case object unchanged (Zend parity).

Compliance guard test/compliance/cases/language/enum_object_cast.phpt is red (verified 2026-06-19).

php-src reference

Repro

<?php
declare(strict_types=1);

enum E: int { case A = 1; }
enum U { case X; }

$o = (object) E::A;
var_export($o === E::A);
echo "\n";
var_export($o instanceof E);
echo "\n";
var_export($o);
echo "\n";

$ux = U::X;
$o2 = (object) $ux;
var_export($o2 === U::X);
echo "\n";
var_export($o2 instanceof U);
echo "\n";
./script/docker-exec.sh php bin/vm.php test/repro-maintainer/enum_object_cast.php
# Today: false / false / (object) array () / false / false
# Zend: true / true / \E::A / true / true

Scope (this repo)

Path Work
lib/VM/EnumCaseSupport.php Enum cast / object cast path
lib/VM.php TYPE_CAST_OBJECT on enum operands
lib/JIT/ Match VM when JIT compiles casts
Tests test/compliance/cases/language/enum_object_cast.phpt green

Done when (php-src-strict)

  • Repro and compliance PHPT match Zend (=== identity + instanceof for backed and unit enums)
  • JIT/AOT cast lowering agrees with VM when in scope
  • No new C runtime branches — PHP lowering in lib/ / ext/

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

    IMPORTANTCritical patharea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions