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

Create instance of enum from same enum in constructor #83

Merged
merged 2 commits into from
Feb 4, 2019

Conversation

KartaviK
Copy link
Contributor

What? - New feature
Will BC break - No

Problem:

Lets create MyEnum

<?php

final class MyEnum extends \MyCLabs\Enum\Enum
{
    public const MY_VALUE = 'test-value';
}

Trying to create instance:

<?php

$enum = new MyEnum(MyEnum::MY_VALUE); // perfectly created

And what if you create an enumeration from the same enumeration?

<?php

$sameEnum = new MyEnum($enum); // will catch semantically incorrect exception

Thrown exception:
Value 'test-value' is not part of MyEnum. But 'test-value' IS part of MyEnum.
This message looks like because __toString() method returns property value in string type if it is not override

This PR add simple logic to checking argument in constructor on instance of static and not throw exception if it is.

It will prevent incorrect semantic exception message
@mnapoli
Copy link
Member

mnapoli commented Feb 4, 2019

Thank you!

@mnapoli mnapoli merged commit 5b9c57d into myclabs:master Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants