-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add support for final constants #6878
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6fc677
Add support for final constants
kocsismate 14c05ea
Make interface constants overridable by default
kocsismate 22244d1
Address review comments
kocsismate cd2506f
Fix constant inheritance check
nikic b46cf28
Use correct constants table
nikic 0fbf3fe
Improve error message
nikic 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Class constants support the final modifier | ||
--FILE-- | ||
<?php | ||
|
||
class Foo | ||
{ | ||
final const A = "foo"; | ||
final public const B = "foo"; | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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,22 @@ | ||
--TEST-- | ||
Interface constants inherited from other interfaces can be redeclared | ||
--FILE-- | ||
<?php | ||
|
||
interface I1 | ||
{ | ||
const C = 1; | ||
} | ||
|
||
interface I2 | ||
{ | ||
const C = 2; | ||
} | ||
|
||
interface I3 extends I1, I2 | ||
{ | ||
const C = 3; | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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,22 @@ | ||
--TEST-- | ||
Class constants cannot be inherited from both a class and an interface | ||
--FILE-- | ||
<?php | ||
|
||
class C | ||
{ | ||
const C = 1; | ||
} | ||
|
||
interface I | ||
{ | ||
const C = 1; | ||
} | ||
|
||
class C2 extends C implements I | ||
{ | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class C2 inherits both C::C and I::C, which is ambiguous in %s on line %d |
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,22 @@ | ||
--TEST-- | ||
Interface constants cannot be inherited from other interfaces | ||
--FILE-- | ||
<?php | ||
|
||
interface I1 | ||
{ | ||
const C = 1; | ||
} | ||
|
||
interface I2 | ||
{ | ||
const C = 2; | ||
} | ||
|
||
interface I3 extends I1, I2 | ||
{ | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class I3 inherits both I1::C and I2::C, which is ambiguous in %s on line %d |
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,18 @@ | ||
--TEST-- | ||
Final class constants cannot be overridden | ||
--FILE-- | ||
<?php | ||
|
||
class Foo | ||
{ | ||
final const A = "foo"; | ||
} | ||
|
||
class Bar extends Foo | ||
{ | ||
const A = "bar"; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Bar::A cannot override final constant Foo::A in %s on line %d |
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,13 @@ | ||
--TEST-- | ||
Private class constants cannot be final | ||
--FILE-- | ||
<?php | ||
|
||
class Foo | ||
{ | ||
private final const A = "foo"; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Private constant Foo::A cannot be final as it is not visible to other classes in %s on line %d |
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-- | ||
Interface constants can be overridden directly | ||
--FILE-- | ||
<?php | ||
|
||
interface I | ||
{ | ||
const X = 1; | ||
} | ||
|
||
class C implements I | ||
{ | ||
const X = 2; | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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,18 @@ | ||
--TEST-- | ||
Final interface constants cannot be overridden directly | ||
--FILE-- | ||
<?php | ||
|
||
interface I | ||
{ | ||
final public const X = 1; | ||
} | ||
|
||
class C implements I | ||
{ | ||
const X = 2; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::X cannot override final constant I::X in %s on line %d |
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,16 @@ | ||
--TEST-- | ||
Final interface constants can be inherited | ||
--FILE-- | ||
<?php | ||
|
||
interface I | ||
{ | ||
final public const X = 1; | ||
} | ||
|
||
class C implements I | ||
{ | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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,19 @@ | ||
--TEST-- | ||
Interface constants can be overridden indirectly | ||
--FILE-- | ||
<?php | ||
|
||
interface I | ||
{ | ||
const X = 1; | ||
} | ||
|
||
class C implements I {} | ||
|
||
class D extends C | ||
{ | ||
const X = 2; | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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,22 @@ | ||
--TEST-- | ||
Class constants cannot be inherited from two different interfaces | ||
--FILE-- | ||
<?php | ||
|
||
interface I1 | ||
{ | ||
const C = 1; | ||
} | ||
|
||
interface I2 | ||
{ | ||
const C = 1; | ||
} | ||
|
||
class C implements I1, I2 | ||
{ | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class C inherits both I1::C and I2::C, which is ambiguous in %s on line %d |
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,22 @@ | ||
--TEST-- | ||
Class constants inherited from interfaces can be redeclared | ||
--FILE-- | ||
<?php | ||
|
||
interface I1 | ||
{ | ||
const C = 1; | ||
} | ||
|
||
interface I2 | ||
{ | ||
const C = 2; | ||
} | ||
|
||
class C implements I1, I2 | ||
{ | ||
const C = 3; | ||
} | ||
|
||
?> | ||
--EXPECT-- |
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 was deleted.
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
Oops, something went wrong.
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.