-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] fix support for unset properties on PHP < 7.4 #44111
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
Conversation
b103717
to
2f52fa9
Compare
After I merged the new test cases in 5.4, they fails, because in 5.4 we have #43469 that changed the logic on the topic. |
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] fix support for lazy properties | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows #44111 Commits ------- 36ee39f [Serializer] fix support for lazy properties
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] fix reading unset properties | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows #44111 (comment) Commits ------- a86f586 [Serializer] fix reading unset properties
@nicolas-grekas in my opinion the fix added in this PR should be implemented in some other way... That would be helpful if this PR had a link to the issue describing the bug you are fixing here, but anyway the key point here is
It's essentially wrong to rely on object state (values of its properties) while building the list of attributes in So, I'd suggest reviewing the code added in this PR to find another way of fixing the bug that this PR is supposed to fix. There is no way to fix issue #36594 as long as
|
@ivannemets-sravniru the behavior changed in 5.4 after your PR, but older branches still remain sensitive to the object state. This PR builds on that. In 5.4, I've adapted the code to follow your lead, aka make it not rely on the object's state. It took me a few commits but please find the diff on 5.4 here: |
@nicolas-grekas the diff looks good to me, the only question is - why this part has been removed from if (\PHP_VERSION_ID >= 70400) {
$this->defaultContext[self::SKIP_UNINITIALIZED_VALUES] = true;
} This was added to make the serializer to ignore uninitialized values by default, and this behavior was assumed in related doc PR https://github.com/symfony/symfony-docs/pull/15823/files Still, I should had set the default value before parent constructor gets called, like this: public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, callable $objectClassResolver = null, array $defaultContext = [])
{
if (\PHP_VERSION_ID >= 70400 && !isset($defaultContext[self::SKIP_UNINITIALIZED_VALUES])) {
$defaultContext[self::SKIP_UNINITIALIZED_VALUES] = true;
}
parent::__construct($classMetadataFactory, $nameConverter, $defaultContext); just to make it possible to configure SKIP_UNINITIALIZED_VALUES by passing it to constructor via DI So, SKIP_UNINITIALIZED_VALUES should be set to true by default, or documentation should be updated to reflect this change |
|
Yes, you are right, I didn't notice that the fallback value for |
Great thanks for the review! |
This bug is why the CI fails on 5.3 currently.