1.2.825. 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.825.1. Specs

Short name

Classes/NoReadonlyAssignationInGlobal

Rulesets

All, Analyze, Changed Behavior, Class Review

Exakat since

2.4.2

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

readonly, class-invasion

Available in

Entreprise Edition, Exakat Cloud