Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed Enum values should not be accepted #2

Open
tuscanicz opened this issue Apr 14, 2020 · 0 comments
Open

Mixed Enum values should not be accepted #2

tuscanicz opened this issue Apr 14, 2020 · 0 comments
Milestone

Comments

@tuscanicz
Copy link
Owner

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
@tuscanicz tuscanicz added this to the v3.x milestone Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant