@@ -84,7 +84,12 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
8484 }
8585 continue ;
8686 }
87- if ($ className !== false && (Bootstrap::$ staticObjectManager ->getScope ($ className ) === Configuration::SCOPE_SINGLETON || $ className === DependencyProxy::class)) {
87+ if ($ className !== false &&
88+ (
89+ Bootstrap::$ staticObjectManager ->getScope ($ className ) === Configuration::SCOPE_SINGLETON
90+ || Bootstrap::$ staticObjectManager ->getScope ($ className ) === Configuration::SCOPE_SESSION
91+ || $ className === DependencyProxy::class
92+ )) {
8893 continue ;
8994 }
9095 }
@@ -114,7 +119,18 @@ private function Flow_searchForEntitiesAndStoreIdentifierArray(string $path, mix
114119 throw new \RuntimeException (sprintf ('The class "%s" has an entity reference Flow could not detect, please add a Flow \\Proxy annotation with "forceSerializationCode" set to "true". ' , 1756936954 ));
115120 }
116121 $ this ->Flow_Persistence_RelatedEntitiesContainer ->appendRelatedEntity ($ originalPropertyName , $ path , $ propertyValue );
117- $ this ->$ originalPropertyName = Arrays::setValueByPath ($ this ->$ originalPropertyName , $ path , null );
122+ /**
123+ * The idea of setting to null here is to prevent serialization after we found an entity, BUT this logic
124+ * is heavily flawed in today's PHP world. Type hinting might make null an invalid value. Also
125+ * Arrays::setValueByPath() only works on "Array-like" not on objects, therefore
126+ * we don't handle direct properties of $this (path empty string) at all here.
127+ * They are skipped for serialization in Flow_serializeRelatedEntities so we don't need to unset.
128+ * This still leaves the option of types going awry somewhere, but at the moment there
129+ * isn't really a better solution at hand and the case should be super rare.
130+ */
131+ if ($ path !== '' ) {
132+ $ this ->$ originalPropertyName = Arrays::setValueByPath ($ this ->$ originalPropertyName , $ path , null );
133+ }
118134 $ foundEntity = true ;
119135 }
120136
@@ -132,11 +148,11 @@ private function Flow_setRelatedEntities(): void
132148 if (isset ($ this ->Flow_Persistence_RelatedEntitiesContainer )) {
133149 $ persistenceManager = Bootstrap::$ staticObjectManager ->get (PersistenceManagerInterface::class);
134150 foreach ($ this ->Flow_Persistence_RelatedEntitiesContainer as $ entityInformation ) {
135- $ entity = $ persistenceManager ->getObjectByIdentifier ($ entityInformation ['identifier ' ], $ entityInformation ['entityType ' ], true );
136- if (isset ($ entityInformation ['entityPath ' ])) {
137- $ this ->{$ entityInformation ['propertyName ' ]} = Arrays::setValueByPath ($ this ->{$ entityInformation ['propertyName ' ]}, $ entityInformation ['entityPath ' ], $ entity );
151+ $ entity = $ persistenceManager ->getObjectByIdentifier ($ entityInformation ['i ' ], $ entityInformation ['c ' ], true );
152+ if (isset ($ entityInformation ['p ' ])) {
153+ $ this ->{$ entityInformation ['n ' ]} = Arrays::setValueByPath ($ this ->{$ entityInformation ['n ' ]}, $ entityInformation ['p ' ], $ entity );
138154 } else {
139- $ this ->{$ entityInformation ['propertyName ' ]} = $ entity ;
155+ $ this ->{$ entityInformation ['n ' ]} = $ entity ;
140156 }
141157 }
142158
0 commit comments