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

object instantiation on return from find* methods #82

Open
flug opened this issue Sep 2, 2024 · 3 comments
Open

object instantiation on return from find* methods #82

flug opened this issue Sep 2, 2024 · 3 comments

Comments

@flug
Copy link

flug commented Sep 2, 2024

Currently, object instantiation is done through a new new $type() closed to the constructor, which requires having setters or public properties outside the constructor.

Therefore, I propose creating an object mapper so that, regardless of where the fields are, the object is correctly rehydrated.

I have started developing a classMapper that takes mappers via a decorator, similar to how the Symfony serializer might work. Would this be suitable? @clementtalleu

@clementtalleu
Copy link
Owner

the initial idea was to impose public methods, but this could be a good solution, we just need to make sure we don't degrade performance (there's no reason to).

@flug
Copy link
Author

flug commented Sep 2, 2024

yeah but it's a bit of a pain because it makes the object inconsistent

@stof
Copy link
Contributor

stof commented Oct 28, 2024

Another option is to do things like the Doctrine ORM and ODM: bypass the public API of the class, by instantiating without calling the constructor and assigning properties using Reflection, which leaves the public API totally free for the needs of the project itself.

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

No branches or pull requests

3 participants