-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for final class constants
RFC: https://wiki.php.net/rfc/final_class_const Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
- Loading branch information
1 parent
c6d4f60
commit a5360e8
Showing
28 changed files
with
340 additions
and
94 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.