Skip to content

Language: backed enum case without value must be compile-time fatal (zend_compile.c) #5397

Description

@PurHur

Category

language / compiler

Problem

For backed enums (enum E: string / enum E: int), every case must declare an explicit backing value. Zend fatals at compile time:

Case A of backed enum E must have a value

This compiler accepts case A; without a value and emits an empty unit-style enum (no fatal).

php-src reference

Repro

test/fixtures/parity/backed_enum_missing_value.php:

<?php
enum E: string {
    case A;
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/fixtures/parity/backed_enum_missing_value.php; echo zend:$?
php bin/vm.php test/fixtures/parity/backed_enum_missing_value.php; echo vm:$?
'
Engine Result
Zend PHP 8.2 Fatal: Case A of backed enum E must have a value
VM Compiles silently (exit 0)

Scope

Area Files
Compiler enum declaration lowering / lib/Compiler/ enum validation
Tests compliance phpt

Done when

  • Compile-time fatal matches Zend message (case name, enum name)
  • No enum class is registered when fatal occurs
  • Targeted test green

Links

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:compilerCompiler / CFG / JITarea: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