-
Notifications
You must be signed in to change notification settings - Fork 75
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
serialize/unserialize of records with 'array' columns fails #53
Comments
on branch [serialization-bug]
I could trace down the problem to the custom serialization of Doctrine_Record and Doctrine_Collection. see #54 |
To make it easier to understand the problem. Here is an abstract example of what happens in Doctrine:
This will result in this serialized string:
The problem lies in As far as I know serialize gives every object in the serialized sting a number to reference it later but the calculated number is wrong. I think the problem lies in On serialize PHP serializes
and every node in the result will get a number to reference it later On unserialize we change the order (due to the custom serialization)
and fail because arrayField is out of order. |
Attention: This bug can also lead to corrupt data. If the |
PHP does not support the double serialization, very weird. <?php
$value = [['foo'], 'bar'];
$serialized = $value;
$serialized[0] = serialize($serialized[0]);
$serialized = serialize($serialized);
$unserialized = unserialize($serialized);
$unserialized[0] = unserialize($unserialized[0]);
$value == $unserialized // true |
@alquerci your example should work and works. The problem only exists if serialize uses references in the serialized string. As in my abstract example we use in |
Here a shorter example to illustrate the problem
|
Another prerequisite is that you use double serialization in a custom serialize function. Outside of
|
This bug happens only on edge cases. Let me describe the scenario first:
schema.yml:
Important here is that 'Model' contains a column of type 'array' and 'Model' has a 'RelatedModel'.
Now the database content:
The database should contain at least one 'Model' (id: 1) connected with one 'RelatedModel' (id: 1).
The 'Model'.'details' should contain an array with at least 20 entries.
Now lets provoke the error. I found these two methods:
Method 1: Load form database with cache
If this query hits the cache the unserialize will fail.
Method 2: serialize/unserialize with references
both of these examples will create an error similar to this:
The text was updated successfully, but these errors were encountered: