Skip to content

Language: enum user methods — parse + VM dispatch (Zend zend_enum.c parity) #3390

Description

@PurHur

Category

language

Problem

Plain enums with user-defined methods fail at parse/CFG time today. The php-cfg enum stmt constructor receives the methods block where $implements should be, so any enum body with methods crashes before VM lowering.

Distinct from #3373 (enum implements Interface); this ticket is enum methods on cases without interface lists.

php-src reference

Repro (failure today)

<?php
enum Status {
    case Ok;
    case Err;
    public function label(): string {
        return $this->name;
    }
}
echo Status::Ok->label(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# TypeError in PHPCfg\Op\Stmt\Enum_::__construct(): Argument #3 ($implements) must be of type array, PHPCfg\Block given

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php repro.php'
# Ok / Err labels on Zend PHP 8.1+

Scope

Module Path
Parser / CFG vendor/ircmaxell/php-cfg enum stmt + patch in patches/ if needed
Compiler lib/Compiler.php enum lowering
VM lib/VM.php enum case object method dispatch
Tests test/compliance/cases/language/enum_user_method.phpt

Done when

Notes

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