File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -504,6 +504,10 @@ protected function mapByReference(&$data)
504
504
continue ;
505
505
}
506
506
507
+ if (PHP_VERSION >= 8.1 && $ property ->isReadOnly () && $ property ->class !== $ reflection ->name ) {
508
+ continue ;
509
+ }
510
+
507
511
$ value = $ property ->getValue ($ instance );
508
512
509
513
if (is_array ($ value ) || is_object ($ value )) {
Original file line number Diff line number Diff line change @@ -183,6 +183,28 @@ enum SerializerScopedBackedEnum: string {
183
183
);
184
184
})->with ('serializers ' );
185
185
186
+ test ('readonly properties declared in parent ' , function () {
187
+ $ childWithDefaultValue = new SerializerPhp81Child ();
188
+
189
+ $ f = static function () use ($ childWithDefaultValue ) {
190
+ return $ childWithDefaultValue ;
191
+ };
192
+
193
+ $ f = s ($ f );
194
+
195
+ expect ($ f ()->property )->toBe (1 );
196
+
197
+ $ child = new SerializerPhp81Child (100 );
198
+
199
+ $ f = static function () use ($ child ) {
200
+ return $ child ;
201
+ };
202
+
203
+ $ f = s ($ f );
204
+
205
+ expect ($ f ()->property )->toBe (100 );
206
+ })->with ('serializers ' );
207
+
186
208
test ('first-class callable with closures ' , function () {
187
209
$ f = function ($ value ) {
188
210
return $ value ;
@@ -584,6 +606,15 @@ enum SerializerScopedBackedEnum: string {
584
606
interface SerializerPhp81HasId {}
585
607
interface SerializerPhp81HasName {}
586
608
609
+ class SerializerPhp81Child extends SerializerPhp81Parent {}
610
+
611
+ class SerializerPhp81Parent
612
+ {
613
+ public function __construct (
614
+ public readonly int $ property = 1 ,
615
+ ) {}
616
+ }
617
+
587
618
class SerializerPhp81Service implements SerializerPhp81HasId, SerializerPhp81HasName
588
619
{
589
620
final public const X = 'foo ' ;
You can’t perform that action at this time.
0 commit comments