Readonly class %s cannot use trait with a non-readonly property %s::$%s¶
Description¶
When a class is readonly, then even the properties added to the class from a trait have to be readonly. Since a trait cannot be readonly, like a class, then each of the properties in the trait, have to be readonly.
Also, note that PHP checks all the traits and the traits of the traits, for readonly properties.
Example¶
<?php
trait T {
private $property;
}
readonly class X {
use T;
}
?>
Literal Examples¶
Readonly class x cannot use trait with a non-readonly property t::$a
Solutions¶
Remove the readonly on the class and apply to all each property in the class.
Make each of the property in the trait, and its dependencies, readonly.