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

Conversation

MrMeshok
Copy link
Contributor

@MrMeshok MrMeshok commented Nov 6, 2024

If you try to serialize an object that has readonly properties that declared in parent, you will get an error "Cannot initialize readonly property Parent::$property from scope Child". This PR fixes this

class Parent
{
    public function __construct(
        public readonly int $property = 1,
    ) {}
}

class Child extends Parent {}

$object = new Child();

$closure = static fn () => $object;

serialize(new \Laravel\SerializableClosure\SerializableClosure($closure));

@taylorotwell taylorotwell marked this pull request as draft November 7, 2024 22:08
@MrMeshok MrMeshok marked this pull request as ready for review November 14, 2024 09:01
@MrMeshok MrMeshok requested a review from nunomaduro November 14, 2024 09:01
@MrMeshok MrMeshok force-pushed the fix-readonly-properties-in-parent branch from 8532715 to 63c06cd Compare November 14, 2024 09:05
@taylorotwell taylorotwell marked this pull request as draft November 14, 2024 18:18
@taylorotwell
Copy link
Member

Drafting pending review from @nunomaduro

@nunomaduro nunomaduro marked this pull request as ready for review November 14, 2024 18:31
Copy link
Member

@nunomaduro nunomaduro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it locally, and seems to be working.

@taylorotwell taylorotwell merged commit 4f48ade into laravel:master Nov 14, 2024
14 checks passed
@MrMeshok MrMeshok deleted the fix-readonly-properties-in-parent branch November 15, 2024 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants