Skip to content

Mixed Enum values should not be accepted #2

@tuscanicz

Description

@tuscanicz

You can now define following Enum as you can see in AbstractEnumTest::testConstructWithMixed():

class EntityStatusEnum extends AbstractEnum
{

    public const NEW_ENTITY = 'new';
    public const MODIFIED_ENTITY = 2;
    public const SAVED_ENTITY = 'saved';

}

This is fully supported and can cause some issues in integrations.

You can also set value to a null, but the Enum will behave very unpredictably with default value. You can see such an example in AbstractEnumTest ::testConstructWithNullAndMixed().

class EntityStatusMixedTypeWithNullEnum extends AbstractEnum
{

    public const NEW_ENTITY = null;
    public const MODIFIED_ENTITY = 2;
    public const SAVED_ENTITY = 'saved';
    public const DEFAULT_ENTITY_STATUS = 'default-value';

    protected static $defaultValue = self::DEFAULT_ENTITY_STATUS;

}

The goal is to avoid:

  • mixed values of Enums, which will bring even more stricter behavior from which a developer can benefit
  • null values and default values must not be used anymore, because they cause confusion

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions