@@ -123,10 +123,6 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
123
123
124
124
$ this ->defaultContext [self ::EXCLUDE_FROM_CACHE_KEY ] = array_merge ($ this ->defaultContext [self ::EXCLUDE_FROM_CACHE_KEY ] ?? [], [self ::CIRCULAR_REFERENCE_LIMIT_COUNTERS ]);
125
125
126
- if (\PHP_VERSION_ID >= 70400 ) {
127
- $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ] = true ;
128
- }
129
-
130
126
$ this ->propertyTypeExtractor = $ propertyTypeExtractor ;
131
127
132
128
if (null === $ classDiscriminatorResolver && null !== $ classMetadataFactory ) {
@@ -194,12 +190,7 @@ public function normalize($object, string $format = null, array $context = [])
194
190
try {
195
191
$ attributeValue = $ this ->getAttributeValue ($ object , $ attribute , $ format , $ attributeContext );
196
192
} catch (UninitializedPropertyException $ e ) {
197
- if ($ this ->shouldSkipUninitializedValues ($ context )) {
198
- continue ;
199
- }
200
- throw $ e ;
201
- } catch (\Error $ e ) {
202
- if ($ this ->shouldSkipUninitializedValues ($ context ) && $ this ->isUninitializedValueError ($ e )) {
193
+ if ($ context [self ::SKIP_UNINITIALIZED_VALUES ] ?? $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ] ?? true ) {
203
194
continue ;
204
195
}
205
196
throw $ e ;
@@ -733,22 +724,4 @@ private function getCacheKey(?string $format, array $context)
733
724
return false ;
734
725
}
735
726
}
736
-
737
- private function shouldSkipUninitializedValues (array $ context ): bool
738
- {
739
- return $ context [self ::SKIP_UNINITIALIZED_VALUES ]
740
- ?? $ this ->defaultContext [self ::SKIP_UNINITIALIZED_VALUES ]
741
- ?? false ;
742
- }
743
-
744
- /**
745
- * This error may occur when specific object normalizer implementation gets attribute value
746
- * by accessing a public uninitialized property or by calling a method accessing such property.
747
- */
748
- private function isUninitializedValueError (\Error $ e ): bool
749
- {
750
- return \PHP_VERSION_ID >= 70400
751
- && str_starts_with ($ e ->getMessage (), 'Typed property ' )
752
- && str_ends_with ($ e ->getMessage (), 'must not be accessed before initialization ' );
753
- }
754
727
}
0 commit comments