Skip to content

False error for enum case value in static property initializer #342

Description

@davidlecce

Describe the bug
PDT incorrectly reports an error when accessing enum case values (->value) inside a static class property initializer. The same code works correctly at runtime and is valid in PHP 8.1+. Moving the same expression into a method removes the error, suggesting a parser limitation.

Describe the eclipse environment
eclipse 2026-03
PDT - 8.4

Expected behavior
No errors in the IDE
This is valid PHP 8.1+ syntax
Code runs correctly

Actual behavior
IDE error Constant expression contains invalid operations

<?php

declare(strict_types=1);

enum ExampleKey: string
{
    case FOO = 'foo';
    case BAR = 'bar';
}

class ExampleClass
{
    private static array $DATA = [
        ['id' => null, 'label' => 'None'],
        ['id' => ExampleKey::FOO->value, 'label' => 'Foo'],
        ['id' => ExampleKey::BAR->value, 'label' => 'Bar'],
    ];

    public static function getData(): array
    {
        return self::$DATA;
    }
}```

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions