Skip to content

Regression: enum typed property/static defaults — compile rejects enum case singleton (re-#5891, zend_compile.c) #9435

Description

@PurHur

Category

language — php-src-strict compile-time enum case defaults

Problem

Typed property and static property defaults using an enum case singleton (Status::Active, Mode::On) fail at compile with Cannot use int/string as default value for property … of type E. Zend accepts the enum case expression and initializes the property to the enum object.

Regression of closed #5891 / #3803 — compliance guard test/compliance/cases/language/enum_property_default.phpt is red again.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/compliance/cases/language/enum_property_default.phpt'

Minimal inline:

<?php
enum Status: string { case Active = 'active'; }
class Config { public static Status $state = Status::Active; }
class Device { public Status $mode = Status::Active; }

Zend: compiles; Config::$state and (new Device())->mode are enum objects.

This compiler (bin/vm.php):

parseAndCompile failure: Cannot use string as default value for property Config::$state of type Status

Scope (PHP-in-PHP)

  • lib/Compiler.php — property/static default validation for enum case operands
  • lib/JIT/Builtin/Type/Object_.phpstatic enum case property default lowering helpers
  • lib/VM/EnumCaseSupport.php — enum case singleton materialization for defaults
  • Avoid new C runtime branches; reuse compile-time enum case registry from class const inits

Done when (php-src-strict)

  • php bin/vm.php test/compliance/cases/language/enum_property_default.phpt matches Zend (\Status::Active static-same, \Mode::On instance-same).
  • enum_property_default_jit.phpt green when JIT in scope.
  • Backed int and string enums work for instance + static typed defaults.

Related

#5891 (closed), #7399 (enum ->value in defaults), #1492 self-host compile spine.

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 features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions