Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Cannot hydrate readonly properties #656

Open
pounard opened this issue Sep 13, 2023 · 2 comments · May be fixed by #657
Open

Cannot hydrate readonly properties #656

pounard opened this issue Sep 13, 2023 · 2 comments · May be fixed by #657

Comments

@pounard
Copy link
Contributor

pounard commented Sep 13, 2023

It seems very normal in the end, since that readonly properties can only be initialized from constructor, but since I mostly bypass constructors to hydrate all object values at once, I end up on this error:

Cannot initialize readonly property App\Domain\Bibliotheque\Model\ContenuBibliotheque::$id from scope GeneratedHydratorGeneratedClass\__PM__\App\Domain\Bibliotheque\Model\ContenuBibliotheque\YToxOntzOjc6ImZhY3RvcnkiO3M6NDE6IkdlbmVyYXRlZEh5ZHJhdG9yXEZhY3RvcnlcSHlkcmF0b3JGYWN0b3J5Ijt9

I wonder if there's a trick to bypass this ?

@pounard
Copy link
Contributor Author

pounard commented Sep 13, 2023

After some random searches on the internet I found this https://stackoverflow.com/questions/71530777/how-do-i-change-a-readonly-property-using-reflection-in-php-8-1 which points to https://3v4l.org/mis1l#v8.1.0

I don't like this ugly hack but in the end, the generated hydrator is using the very ulgy closure hack itself, and implementation won't matter for users, as soon as it works as expected.

Should I attempt an implementation of this ?

pounard added a commit to pounard/GeneratedHydrator that referenced this issue Sep 13, 2023
@pounard
Copy link
Contributor Author

pounard commented Sep 13, 2023

And done, cf. linked PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant