Readonly property %s::$%s cannot have default value

Description

A readonly property is expected to be set once, and only once, at execution time. Then, it is not changed anymore.

A property, whose value is known at compilation time should probably be a constant.

Example

<?php

class T {
     public readonly int $i = 1;
}

?>

Literal Examples

  • Readonly property x::$i cannot have default value

Solutions

  • Drop the readonly option.

  • Make the property a class constant.