@@ -705,7 +705,7 @@ class ClassMetadataInfo implements ClassMetadata
705705 /**
706706 * The ReflectionProperty instances of the mapped class.
707707 *
708- * @var ReflectionProperty[] |null[]
708+ * @var array<string, ReflectionProperty|null>
709709 */
710710 public $ reflFields = [];
711711
@@ -993,7 +993,8 @@ public function wakeupReflection($reflService)
993993
994994 foreach ($ this ->embeddedClasses as $ property => $ embeddedClass ) {
995995 if (isset ($ embeddedClass ['declaredField ' ])) {
996- $ childProperty = $ reflService ->getAccessibleProperty (
996+ $ childProperty = $ this ->getAccessibleProperty (
997+ $ reflService ,
997998 $ this ->embeddedClasses [$ embeddedClass ['declaredField ' ]]['class ' ],
998999 $ embeddedClass ['originalField ' ]
9991000 );
@@ -1007,7 +1008,8 @@ public function wakeupReflection($reflService)
10071008 continue ;
10081009 }
10091010
1010- $ fieldRefl = $ reflService ->getAccessibleProperty (
1011+ $ fieldRefl = $ this ->getAccessibleProperty (
1012+ $ reflService ,
10111013 $ embeddedClass ['declared ' ] ?? $ this ->name ,
10121014 $ property
10131015 );
@@ -1020,15 +1022,15 @@ public function wakeupReflection($reflService)
10201022 if (isset ($ mapping ['declaredField ' ]) && isset ($ parentReflFields [$ mapping ['declaredField ' ]])) {
10211023 $ this ->reflFields [$ field ] = new ReflectionEmbeddedProperty (
10221024 $ parentReflFields [$ mapping ['declaredField ' ]],
1023- $ reflService ->getAccessibleProperty ($ mapping ['originalClass ' ], $ mapping ['originalField ' ]),
1025+ $ this ->getAccessibleProperty ($ reflService , $ mapping ['originalClass ' ], $ mapping ['originalField ' ]),
10241026 $ mapping ['originalClass ' ]
10251027 );
10261028 continue ;
10271029 }
10281030
10291031 $ this ->reflFields [$ field ] = isset ($ mapping ['declared ' ])
1030- ? $ reflService ->getAccessibleProperty ($ mapping ['declared ' ], $ field )
1031- : $ reflService ->getAccessibleProperty ($ this ->name , $ field );
1032+ ? $ this ->getAccessibleProperty ($ reflService , $ mapping ['declared ' ], $ field )
1033+ : $ this ->getAccessibleProperty ($ reflService , $ this ->name , $ field );
10321034
10331035 if (isset ($ mapping ['enumType ' ]) && $ this ->reflFields [$ field ] !== null ) {
10341036 $ this ->reflFields [$ field ] = new ReflectionEnumProperty (
@@ -1040,8 +1042,8 @@ public function wakeupReflection($reflService)
10401042
10411043 foreach ($ this ->associationMappings as $ field => $ mapping ) {
10421044 $ this ->reflFields [$ field ] = isset ($ mapping ['declared ' ])
1043- ? $ reflService ->getAccessibleProperty ($ mapping ['declared ' ], $ field )
1044- : $ reflService ->getAccessibleProperty ($ this ->name , $ field );
1045+ ? $ this ->getAccessibleProperty ($ reflService , $ mapping ['declared ' ], $ field )
1046+ : $ this ->getAccessibleProperty ($ reflService , $ this ->name , $ field );
10451047 }
10461048 }
10471049
@@ -3779,4 +3781,17 @@ private function assertMappingOrderBy(array $mapping): void
37793781 throw new InvalidArgumentException ("'orderBy' is expected to be an array, not " . gettype ($ mapping ['orderBy ' ]));
37803782 }
37813783 }
3784+
3785+ /**
3786+ * @psalm-param class-string $class
3787+ */
3788+ private function getAccessibleProperty (ReflectionService $ reflService , string $ class , string $ field ): ?ReflectionProperty
3789+ {
3790+ $ reflectionProperty = $ reflService ->getAccessibleProperty ($ class , $ field );
3791+ if ($ reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $ reflectionProperty ->isReadOnly ()) {
3792+ $ reflectionProperty = new ReflectionReadonlyProperty ($ reflectionProperty );
3793+ }
3794+
3795+ return $ reflectionProperty ;
3796+ }
37823797}
0 commit comments