rfc:allow-constant-override-consistently
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:allow-constant-override-consistently [2018/04/11 02:26] – created wesnetmo | rfc:allow-constant-override-consistently [2018/04/14 04:56] (current) – wesnetmo | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC - Allow constant override | + | ====== PHP RFC - Consistent class-constant override ====== |
* Version: 0.0.1 | * Version: 0.0.1 | ||
* Date: 2018-04-11 | * Date: 2018-04-11 | ||
- | * Author: WesNetmo | + | * Author: |
* Status: Under Discussion | * Status: Under Discussion | ||
* First Published at: https:// | * First Published at: https:// | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Currently, a class constant can be overridden in inheritors, but the same cannot be achieved when interfaces | + | Currently, a class constant can be overridden in inheritors, but it's disallowed in interfaces. |
<code php> | <code php> | ||
Line 20: | Line 20: | ||
interface B2 extends A2 { const X = 2; } | interface B2 extends A2 { const X = 2; } | ||
+ | // This doesn' | ||
interface A3 { const X = 1; } | interface A3 { const X = 1; } | ||
class B3 implements A3 { const X = 2; } | class B3 implements A3 { const X = 2; } | ||
</ | </ | ||
- | Even if this restriction had a purpose, it's not really effective since the restriction | + | Even if this restriction had a purpose, it's not really effective since it has only effect in direct inheritors: |
<code php> | <code php> | ||
+ | // This works: | ||
interface A3 { const X = 1; } | interface A3 { const X = 1; } | ||
abstract class B3 implements A3 { } // Can't override here | abstract class B3 implements A3 { } // Can't override here | ||
Line 34: | Line 36: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to normalize the behavior so that constant override is allowed everywhere. This is not an invite at reckless overriding but simply a matter of consistency. Class constants are constants only within the class they are defined in; inheritors | + | This RFC proposes to normalize the behavior so that constant override is allowed everywhere. This is not an invite at reckless overriding but simply a matter of consistency. Class constants are **constants only within the class they are defined in**; child classes |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 43: | Line 45: | ||
7.3 | 7.3 | ||
+ | |||
+ | ===== Future scope: ===== | ||
+ | |||
+ | If desired by the community, the ''' | ||
===== Voting ===== | ===== Voting ===== | ||
Line 50: | Line 56: | ||
===== References ===== | ===== References ===== | ||
- | - [[https:// | + | - [[...........|Discussion on externals]] |
rfc/allow-constant-override-consistently.1523413589.txt.gz · Last modified: 2018/04/11 02:26 by wesnetmo