Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for readonly properties that declared in parent #96

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Serializers/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ protected function mapByReference(&$data)
continue;
}

if (PHP_VERSION >= 8.1 && $property->isReadOnly() && $property->class !== $reflection->name) {
continue;
}

$value = $property->getValue($instance);

if (is_array($value) || is_object($value)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/SerializerPhp81Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ enum SerializerScopedBackedEnum: string {
);
})->with('serializers');

test('readonly properties declared in parent', function () {
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
$controller = new SerializerPhp81ControllerChild();

$f = static function () use ($controller) {
return $controller;
};

$f = s($f);

expect($f()->service)->toBeInstanceOf(
SerializerPhp81Service::class,
);
})->with('serializers');

test('first-class callable with closures', function () {
$f = function ($value) {
return $value;
Expand Down Expand Up @@ -589,6 +603,8 @@ class SerializerPhp81Service implements SerializerPhp81HasId, SerializerPhp81Has
final public const X = 'foo';
}

class SerializerPhp81ControllerChild extends SerializerPhp81Controller {}

class SerializerPhp81Controller
{
public function __construct(
Expand Down