rfc:allow-constant-override-consistently
Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
rfc:allow-constant-override-consistently [2018/04/11 02:26] – created wesnetmo | rfc:allow-constant-override-consistently [2018/04/11 02:34] – 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; } | ||
Line 27: | Line 28: | ||
<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 50: | Line 52: | ||
===== References ===== | ===== References ===== | ||
- | - [[https:// | + | - [[...........|Discussion on externals]] |
rfc/allow-constant-override-consistently.txt · Last modified: 2018/04/14 04:56 by wesnetmo