- Notifications
You must be signed in to change notification settings - Fork 37
handle class constant visibility added in PHP-7.1 #59
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
Conversation
| Hardware question. Maybe make it configurable? |
d6dea6c to 1b384b2 Compare | After thinking about it, I find that only public consts should be part of the enumeration. At least by default. I don't have a use case at hand, but private or protected consts should only be allowed via a switch enabling this feature in the constructor. |
| I also feel that only public constants makes sense as enumeration members. Having a switch is somewhat problematic as an enumeration should be seen as a type implement with a lot of static member features here. I need to check how to detect public constants only - need to compile PHP-7.1 locally as it's not fun to develop with travis as environment ;)
|
9550ea7 to 431c0e4 Compare bb6c6ef to f0156d8 Compare | works now -> only public constants are used as enumerators |
prolic left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goods, just some minor things to clean up
src/Enum.php Outdated
| $scopeConstants = array(); | ||
| if (PHP_VERSION_ID >= 70100) { | ||
| // Since PHP-7.1 visibility modifiers are allowed for class constants | ||
| // for enumerations we are only interected in public once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/s/interected/interested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| protected const PRO2 = 'protected extended'; | ||
| private const PRI2 = 'private extended'; | ||
| } | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one new line too much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| protected const PRO = 'protected'; | ||
| private const PRI = 'private'; | ||
| } | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one new line too much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| | ||
| public function testConstVisibilityExtended() | ||
| { | ||
| if (PHP_VERSION_ID < 70100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better like this:
version_compare(PHP_VERSION, '7.1', '<')
| | ||
| public function testConstVisibility() | ||
| { | ||
| if (PHP_VERSION_ID < 70100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better like this:
version_compare(PHP_VERSION, '7.1', '<')
| | ||
| do { | ||
| $scopeConstants = array(); | ||
| if (PHP_VERSION_ID >= 70100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better like this:
version_compare(PHP_VERSION, '7.1', '<')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using version_compare() is much much slower than using the integer constant as it first needs to call a function and the function has to parse three strings into two integers and a comparator sign. Instead I'm using the PHP_VERSION_ID integer constant to just do one comparison of two integers ;)
f0156d8 to 71d7b81 Compare | @prolic thanks for review - I fixed everything except the use of |
| perfect |
PHP-7.1 will support Class Constant Visibility
but should
privateand/orprotectedclass constants be part of an enumeration?