1.2.831. No Readonly Assignation In Global¶
When a property is marked readonly, it may only be assigned within the class of definition.
It cannot be assigned outside this class, in the global scope. It is also immune to class invasion.
<?php
class x {
public readonly int $p;
function foo() {
$this->p -= 1; // OK
$x = new x;
$x->p = 1; // Not OK, even if $x is of type x
}
}
$x = new x;
$x->p = 1; // Not OK
?>
1.2.831.2. Connex PHP features¶
1.2.831.2.1. Specs¶
Short name |
Classes/NoReadonlyAssignationInGlobal |
Rulesets |
|
Exakat since |
2.4.2 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |