[php-src] Issue #9285: PHP 8.2 readonly classes allow inheriting mutable properties from traits

From: Date: Tue, 09 Aug 2022 12:09:24 +0000
Subject: [php-src] Issue #9285: PHP 8.2 readonly classes allow inheriting mutable properties from traits
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242163@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9285 Author: TysonAndre ### Description The following code: ```php <?php trait T2{ public $prop; } readonly class G { use T2; } $g = new G(); $g->prop = 123; $g->prop = 124; var_export($g); ``` Resulted in this output: ``` \G::__set_state(array( 'prop' => 124, )) ``` But I expected this output instead: ``` One of the following 1. Making the inherited properties readonly (seems strange and makes trait harder to reason about without knowing about uses) 2. Making it an error to inherit a property from a trait at the time of inheritance when all trait properties are determined (including traits extending other traits) 3. Making it an error to use traits from readonly classes (similar to existing check that makes it an error to extend from non-readonly classes, including classes that have no properties) 4. readonly trait support, which probably requires its own rfc (can only be used by readonly classes and readonly traits?) ``` So far, the only reference to traits in the implementation was just checking that the modifier couldn't be applied to traits (https://github.com/php/php-src/pull/7305/files#diff-3fa220fdd8047943b96515df0805331f7ae6d52a0228084d5e9b491e8f1b01a9) ### PHP Version PHP 8.2.0beta2 ### Operating System _No response_

« previous php.bugs (#242163) next »