rfc:final_properties
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:final_properties [2020/02/18 13:03] – kocsismate | rfc: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, | + | This RFC proposes to add support for a new property modifier that would allow properties to be initialized, |
===== 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 '' | + | "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 '' |
- | As soon as initialization is done, any other attempt | + | As soon as initialization is done, any other attempt |
<code php> | <code php> | ||
Line 21: | Line 21: | ||
final public int $a; | final public int $a; | ||
final public string $b; | final public string $b; | ||
- | final public array $c = []; | + | final public array $c = [" |
final public stdclass $d; | final public stdclass $d; | ||
Line 36: | Line 36: | ||
$foo->b = ""; | $foo->b = ""; | ||
$foo->c = []; // EXCEPTION: property c has already been initialized | $foo->c = []; // EXCEPTION: property c has already been initialized | ||
- | $foo-> | + | $foo-> |
$foo-> | $foo-> | ||
rfc/final_properties.txt · Last modified: 2020/02/18 23:29 by kocsismate