rfc:final_properties

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:final_properties [2020/02/18 13:29] kocsismaterfc:final_properties [2020/02/18 20:29] kocsismate
Line 1: Line 1:
-====== PHP RFC: Final properties ======+====== PHP RFC: Write-Once Properties ======
   * Version: 0.1   * Version: 0.1
   * Date: 2020-02-18   * Date: 2020-02-18
Line 8: Line 8:
  
 ===== Introduction ===== ===== Introduction =====
-This RFC proposes to add support for a new property modifier that would allow properties to be initialized, but not modified afterwards. For example, Java and C# also have similar - but not exactly the same - concept.+This RFC proposes to add support for a new property modifier that would allow properties to be initialized, but not modified afterwards. This feature would be useful in situations where one wants to guarantee that a property remains the same for the lifetime of an object - which is usually the case for Value Objects or Data Transfer Objects. Other languageslike Java and C# also have similar - but not exactly the same - concepts for a long time (''final'' and ''readonly'' respectively).
  
 ===== Proposal ===== ===== Proposal =====
-"Final" properties in PHP (the actual keyword is to be decided) could be initialized either by an explicit default value, or by assigning a value to them. Unlike to ''final'' properties in Java, this RFC proposes to allow the initialization of object properties after object construction. The main purpose of this is to make lazy loading possible - which is an important aspect for many PHP applications. Additionally to object properties, class properties can also use the "final" modifier with the same restrictions.+"Write-once" properties in PHP (the actual keyword is to be decided) could be initialized either by an explicit default value, or by assigning a value to them. Unlike to ''final'' properties in Java, this RFC proposes to allow the initialization of object properties after object construction. The main purpose of this behaviour is to make lazy loading possible - which is an important aspect for many PHP applications. In addition to object properties, class properties can also use the modifier in question with the same restrictions.
  
-As soon as initialization is done, any other attempt to assign a new value to "final" properties would result in an exception as it can be seen below:+As soon as initialization is done, any other attempt to assign a new value to "write-once" properties would result in an exception as it can be seen below:
  
 <code php> <code php>
rfc/final_properties.txt · Last modified: 2020/02/18 23:29 by kocsismate