Case %s of non-backed enum %s must not have a value

Description

An enum is either purely a set of named cases (a pure enum), or it is a backed enum, where every case is associated with an int or string value declared after the enum name, like enum Suit: int.

Once an enum does not declare a backing type, none of its cases may be given a value. Assigning a value to a case, like case Hearts = 1;, requires the enum itself to declare a backing type.

Example

<?php

enum Suit
{
    case Hearts = 1;
    case Spades;
}

?>

Literal Examples

  • Case Hearts of non-backed enum Suit must not have a value

Solutions

  • Remove the value from the case declaration, to keep the enum a pure enum.

  • Add a backing type to the enum declaration, such as enum Suit: int, so every case can carry a value.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.