Constants declared in interfaces have to be public#1840
Merged
TomasVotruba merged 1 commit intorectorphp:masterfrom Aug 11, 2019
scheb:interface-constant
Merged
Constants declared in interfaces have to be public#1840TomasVotruba merged 1 commit intorectorphp:masterfrom scheb:interface-constant
TomasVotruba merged 1 commit intorectorphp:masterfrom
scheb:interface-constant
Conversation
Member
|
Good to know. Do you have any source about that language feature? |
Contributor
Author
|
Couldn't find anything in the official docs, but it's in the PHP source code: https://github.com/php/php-src/blob/master/Zend/zend_API.c#L3786 And it makes sense, since an interface is meant to declare a public contract to be implemented by a class, so allowing private/protected constants there doesn't make much sense. |
Member
|
Too bad it's so hidden. |
Member
|
Thank you for contribution with fix 👍 |
TomasVotruba
added a commit
that referenced
this pull request
Feb 20, 2022
rectorphp/rector-src@5fa9dd9 [EarlyReturn] Refactor RemoveAlwaysElseRector to return array of Nodes to avoid node in else marked as removed (#1840)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Constants declared in an interface have to be
public, havingprivateorprotectedconstants in interfaces is not supported by the language. PHP will error withPHP Fatal error: Access type for interface constant SomeInterface::CONSTANT must be public.So whenever a constant is defined in an interface, we can just make it
public.