rfc:allow-constant-override-consistently

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:allow-constant-override-consistently [2018/04/11 02:26] – created wesnetmorfc:allow-constant-override-consistently [2018/04/14 04:56] (current) wesnetmo
Line 1: Line 1:
-====== PHP RFC - Allow constant override consistently ======+====== 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: Pedro Magalhães, WesNetmo
   * Status: Under Discussion   * Status: Under Discussion
   * First Published at: https://wiki.php.net/rfc/allow-constant-override-consistently   * First Published at: https://wiki.php.net/rfc/allow-constant-override-consistently
Line 9: Line 9:
 ===== Introduction ===== ===== Introduction =====
  
-Currently, a class constant can be overridden in inheritors, but the same cannot be achieved when interfaces are involved.+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't work either:
 interface A3            { const X = 1; } interface A3            { const X = 1; }
 class B3 implements A3  { const X = 2; } class B3 implements A3  { const X = 2; }
 </code> </code>
  
-Even if this restriction had a purpose, it's not really effective since the restriction has only effect in direct inheritors:+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 inherit them by default but the user can optionally override them if desired.+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 inherit them by default but the user can optionally override them if desired.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 43: Line 45:
  
 7.3 7.3
 +
 +===== Future scope: =====
 +
 +If desired by the community, the '''final''' keyword could be introduced in order to actually prevent constant override.
  
 ===== Voting ===== ===== Voting =====
Line 50: Line 56:
 ===== References ===== ===== References =====
  
-- [[https://externals.io/message/101823|Discussion on externals]]+- [[...........|Discussion on externals]]
rfc/allow-constant-override-consistently.1523413589.txt.gz · Last modified: 2018/04/11 02:26 by wesnetmo