Skip to content

Commit b88b3bf

Browse files
authored
Fix bug related to readonly properties (#87)
* fix: Fix bug related to readonly properties * feat: Skip readonly properties for PHP below 8.1 * test: Add test for readonly properties from parent scope variable
1 parent d715a63 commit b88b3bf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Serializers/Native.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ protected function mapPointers(&$data)
378378
continue;
379379
}
380380

381+
if (PHP_VERSION >= 8.1 && $property->isReadOnly()) {
382+
continue;
383+
}
384+
381385
$item = $property->getValue($data);
382386

383387
if ($item instanceof SerializableClosure || $item instanceof UnsignedSerializableClosure || ($item instanceof SelfReference && $item->hash === $this->code['self'])) {

tests/SerializerPhp81Test.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ enum SerializerScopedBackedEnum: string {
169169
});
170170
})->with('serializers');
171171

172+
test('readonly properties from parent scope variable', function () {
173+
$controller = new SerializerPhp81Controller();
174+
175+
$f = static function () use ($controller) {
176+
return $controller;
177+
};
178+
179+
$f = s($f);
180+
181+
expect($f()->service)->toBeInstanceOf(
182+
SerializerPhp81Service::class,
183+
);
184+
})->with('serializers');
185+
172186
test('first-class callable with closures', function () {
173187
$f = function ($value) {
174188
return $value;

0 commit comments

Comments
 (0)