Skip to content

Constants declared in interfaces have to be public#1840

Merged
TomasVotruba merged 1 commit intorectorphp:masterfrom
scheb:interface-constant
Aug 11, 2019
Merged

Constants declared in interfaces have to be public#1840
TomasVotruba merged 1 commit intorectorphp:masterfrom
scheb:interface-constant

Conversation

@scheb
Copy link
Copy Markdown
Contributor

@scheb scheb commented Aug 11, 2019

Constants declared in an interface have to be public, having private or protected constants in interfaces is not supported by the language. PHP will error with PHP 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.

@TomasVotruba
Copy link
Copy Markdown
Member

Good to know. Do you have any source about that language feature?

@scheb
Copy link
Copy Markdown
Contributor Author

scheb commented Aug 11, 2019

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.

@TomasVotruba
Copy link
Copy Markdown
Member

TomasVotruba commented Aug 11, 2019

Too bad it's so hidden.
Thanks for such a research 👍

@TomasVotruba TomasVotruba merged commit 702a317 into rectorphp:master Aug 11, 2019
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you for contribution with fix 👍

@scheb scheb deleted the interface-constant branch August 20, 2019 19:47
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants