[RFC]: ReflectionHydrator
and (un-)initialized property handling
#112
Labels
ReflectionHydrator
and (un-)initialized property handling
#112
RFC
Goal
Skip uninitialized properties in
extract
method.Background
Every hydrator needs an instance of an object to be passed to the methods by-design.
We are currently moving over from non-typed properties to typed properties + constructor promotion.
That works well once the object is instantiated within the code by using the construct but we do also have a scope where we hydrate and extract those objects (don't ask...).
However, at some point, it seems that we do only have a partial set of data to hydrate into the object. Prior typed properties, every property which was not explicitly passed via
data
argument was initialized asnull
and thus, there was not a problem (besides the fact that even that a method/property stated to return an object/string/whatever returned null once you wanted to use that value).So once you extract an object which was not 100% hydrated before leads to an error because the property is not properly initialized.
Considerations
There should be no real impact on users besides the fact that objects with uninitialized properties do behave the same way with and without typed properties (being null in the extracted data).
Proposal(s)
laminas-hydrator/src/ReflectionHydrator.php
Lines 24 to 38 in 15cd4da
We could add a new private method to return
null
for uninitialized properties:Appendix
/
The text was updated successfully, but these errors were encountered: