rfc:readonly_classes
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:readonly_classes [2021/11/22 15:46] – kocsismate | rfc:readonly_classes [2022/04/19 07:55] – kocsismate | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2021-08-04 | * Date: 2021-08-04 | ||
* Author: Máté Kocsis < | * Author: Máté Kocsis < | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.2 | * Target Version: PHP 8.2 | ||
* Implementation: | * Implementation: | ||
Line 34: | Line 34: | ||
$foo = new Foo(); | $foo = new Foo(); | ||
$foo-> | $foo-> | ||
- | // Cannot modify readonly property Foo::$bar | + | // Fatal Error: Uncaught Error: |
$foo-> | $foo-> | ||
- | // Cannot create dynamic property Foo::$baz | + | // Fatal Error: Uncaught Error: |
</ | </ | ||
Line 44: | Line 43: | ||
As neither untyped, nor static properties are covered by the [[rfc: | As neither untyped, nor static properties are covered by the [[rfc: | ||
- | readonly classes cannot declare | + | readonly classes cannot declare them either: |
<PHP> | <PHP> | ||
Line 62: | Line 61: | ||
// Fatal error: Readonly class Foo cannot declare static properties | // Fatal error: Readonly class Foo cannot declare static properties | ||
+ | </ | ||
==== Inheritance ==== | ==== Inheritance ==== | ||
- | Similarly how overriding of readonly properties | + | Similarly how overriding of readonly properties |
<PHP> | <PHP> | ||
- | class A {} | + | readonly |
- | readonly class B extends A {} | + | readonly class B extends A {} // valid |
</ | </ | ||
- | Both of the following are illegal: | + | But both of the following are illegal: |
<PHP> | <PHP> | ||
readonly class A {} | readonly class A {} | ||
class B extends A {} | class B extends A {} | ||
+ | // Fatal error: Non-readonly class B cannot extend readonly class A | ||
</ | </ | ||
Line 83: | Line 83: | ||
class A {} | class A {} | ||
readonly class B extends A {} | readonly class B extends A {} | ||
+ | // Fatal error: Readonly class B cannot extend non-readonly class A | ||
</ | </ | ||
rfc/readonly_classes.txt · Last modified: 2022/08/21 08:47 by kocsismate