Readonly property %s::$%s must have type¶
Description¶
A readonly
property must be typed. It cannot be left without a type. In case of need of a wide range of types, use an union type, or the mixed
keyword.
Example¶
<?php
class X {
private readonly $property;
}
?>
Literal Examples¶
Readonly property X::$property must have type
Solutions¶
Use the
mixed
type to explicitely type the property, but not commit to any constraint.Use an union type to explicitely type the property, and commit to a restricted list of types.
Use the actual type for the property.
Remove the
readonly
option.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Classes/ReadonlyCompatibility.