-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Issue in collections with Symfony 2.6 (maybe in the other versions too) & Doctrine 2.5 #15797
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
Comments
I have symfony 2.7.3 and I have the same exception after upgrading doctrine to 2.5 |
@BboyKeen @h3llr4iser - I am facing the same issue in the 'unscheduleOrphanRemoval' and applied a similar workaround. Is this issue resolved ? |
+1 |
No response from the teams so I don't know. I'm still using the workaround I've provided. |
This is fixed by #16090. |
note that the fix is not yet released. It will be part of the next 2.3.x and 2.7.x releases |
Thank you. |
@ZCJ you can subscribe to the Symfony Roadmap Notifications |
Thanks for the fix ! |
Hey Symfony guys,
After upgrading Doctrine from 2.4 to 2.5, I've been facing a new problem with my collections which were not working well.
The entity association is simple : OneToMany; in my case one User linked to many Skills.
At first sight, this message appeared " 'spl_object_hash() expects parameter 1 to be object, null given' " with no reason.
Here is the stack trace :
After looking at the Doctrine and Symfony code, I think I've spotted the problem.
If my understandings are good, when working with collections, Symfony has to prepare the field of the data_class object to receive potential new elements. This preparation is done at PRE_BIND state by the method "readPropertiesUntil" of PropertyAccessor class (line 191) by initializing new column with "null" value.
As we can see, the missing columns in the array are added thanks to this line :
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
As Doctrine uses ArrayAccess implementation for the PersistentCollection, the use of
$objectOrArray[$property]
is equivalent to a call to theoffsetSet
method located at line 522 in the PersistentCollection class.Then a call to the
set
method is issued :And in my opinion, the problem comes here.
In Doctrine 2.4, the
set
method was :Between these two versions, we can see the introduction of this piece of code :
And
cancelOrphanRemoval
results in :So, when the PropertyAccessor initializes the object to prepare it to receive the new value which will be inserted during the write phase, it issues
unset($this->orphanRemovals[spl_object_hash(null)])
indirectly through the cancelOrphanRemoval method. That's the reason why the exception is produced. This call was not issued in Doctrine 2.4 which explains why there was no problem.As a quick workaround, I've used this
because I don't know if it's the role of Doctrine to restrict null values or the role of Symfony to initialize the PersistentCollection in another way.
Sorry for this very long bugreport,
Keen
The text was updated successfully, but these errors were encountered: