-
Notifications
You must be signed in to change notification settings - Fork 8k
Add values() Method to BackedEnum #20398
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
Open
savinmikhail
wants to merge
10
commits into
php:master
Choose a base branch
from
savinmikhail:enum-values/clean-rewrite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56c0a00
Zend: Add ZEND_STR_VALUES interned string
savinmikhail 4da74a9
Zend: Add BackedEnum::values() static method
savinmikhail 38b650e
Reflection: Include BackedEnum::values() in ReflectionEnum and add re…
savinmikhail 6316025
Tests: Add BackedEnum::values() test suite for enums
savinmikhail 91a9daf
Docs: NEWS, UPGRADING: Document BackedEnum::values()
savinmikhail 941f17c
Zend: Respect user-defined values() on BackedEnum
savinmikhail ae7395a
Tests: Add user-defined BackedEnum::values() override test
savinmikhail b4d9250
Reflection: Add test for user-defined BackedEnum::values()
savinmikhail 72b3c89
Zend: Use EX(func) and avoid tmp zval copy in zend_enum_values_func()
savinmikhail 0095c97
Reflection: Add test for user-defined BackedEnum::values()
savinmikhail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --TEST-- | ||
| Backed enums: values() on empty enum returns [] | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| enum A: string {} | ||
|
|
||
| var_dump(A::values()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(0) { | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --TEST-- | ||
| BackedEnum::values() only returns case values, not regular constants | ||
| --FILE-- | ||
| <?php | ||
| enum Mixed_: string { | ||
| case A = 'a'; | ||
| case B = 'b'; | ||
|
|
||
| public const REGULAR_CONST = 'not_a_case'; | ||
| } | ||
| var_dump(Mixed_::values()); | ||
| ?> | ||
| --EXPECT-- | ||
| array(2) { | ||
| [0]=> | ||
| string(1) "a" | ||
| [1]=> | ||
| string(1) "b" | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --TEST-- | ||
| Backed enums: values() returns ints | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| enum Priority: int { | ||
| case Low = 1; | ||
| case Medium = 5; | ||
| case High = 10; | ||
| } | ||
|
|
||
| var_dump(Priority::values()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(3) { | ||
| [0]=> | ||
| int(1) | ||
| [1]=> | ||
| int(5) | ||
| [2]=> | ||
| int(10) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --TEST-- | ||
| Unit enums do not have values() | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| enum U { | ||
| case A; | ||
| } | ||
|
|
||
| var_dump(method_exists(U::class, 'values')); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(false) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --TEST-- | ||
| BackedEnum::values() preserves declaration order | ||
| --FILE-- | ||
| <?php | ||
| enum Order: int { | ||
| case Third = 3; | ||
| case First = 1; | ||
| case Second = 2; | ||
| } | ||
| var_dump(Order::values()); | ||
| ?> | ||
| --EXPECT-- | ||
| array(3) { | ||
| [0]=> | ||
| int(3) | ||
| [1]=> | ||
| int(1) | ||
| [2]=> | ||
| int(2) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --TEST-- | ||
| Backed enums: values() returns strings | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| enum Color: string { | ||
| case Red = 'red'; | ||
| case Green = 'green'; | ||
| case Blue = 'blue'; | ||
| } | ||
|
|
||
| var_dump(Color::values()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(3) { | ||
| [0]=> | ||
| string(3) "red" | ||
| [1]=> | ||
| string(5) "green" | ||
| [2]=> | ||
| string(4) "blue" | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --TEST-- | ||
| BackedEnum::values() appears in reflection | ||
| --FILE-- | ||
| <?php | ||
| enum Status: string { | ||
| case Active = 'active'; | ||
| } | ||
| $method = new ReflectionMethod(Status::class, 'values'); | ||
| var_dump($method->isStatic()); | ||
| var_dump($method->isPublic()); | ||
| var_dump($method->getNumberOfParameters()); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(true) | ||
| int(0) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.