Skip to content

isValidKey using toArray() directly #16

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

Merged
merged 2 commits into from
Apr 26, 2015
Merged

Conversation

KKKas
Copy link
Contributor

@KKKas KKKas commented Apr 23, 2015

Now it doesn't need to use toArray()->array_keys->in_array, but just toArray() and isset[$key], which should be faster.

Now it doesn't need to use toArray()->array_keys->in_array, but just toArray() and isset[$key], which should be faster.
@mnapoli
Copy link
Member

mnapoli commented Apr 23, 2015

Hi, thanks this is a good change if it improves the performances.

However it fails on PHP 5.3 right now. Furthermore it uses isset() which will return false if an enum value is null (see this: http://3v4l.org/jPC6H). You should use array_key_exists() instead I think.

By the way it's too bad that the tests didn't pick that, maybe if you have time to add some tests you could test that:

class MyEnum extends Enum {
    const FOO = null;
}

$this->assertTrue(MyEnum::isValid(null));
new MyEnum(null); // should work

@mnapoli
Copy link
Member

mnapoli commented Apr 23, 2015

Wait I'm mixing things up… This is isValidKey() so it's impossible to define a constant name null :)

Fixing the PHP 5.3 error should be enough then ;)

PHP < 5.4:
"Fatal error: Can't use function return value in write context in (...)"
@KKKas
Copy link
Contributor Author

KKKas commented Apr 23, 2015

Hey,
Wow, I didn't know http://3v4l.org ;-) That's awesome tool. Thanks.

I think that now isValidKey() should be fine.

mnapoli added a commit that referenced this pull request Apr 26, 2015
isValidKey using toArray() directly
@mnapoli mnapoli merged commit b5ca36f into myclabs:master Apr 26, 2015
@mnapoli
Copy link
Member

mnapoli commented Apr 26, 2015

👍

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