[DBAL-73] Could not convert database value "b:0;" to Doctrine Type object Created: 06/Dec/10 Updated: 12/Dec/10 Resolved: 12/Dec/10 |
|
| Status: | Resolved |
| Project: | Doctrine DBAL |
| Component/s: | None |
| Affects Version/s: | 2.0.0-RC1-RC3 |
| Fix Version/s: | 2.0-RC5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Marcus Speight | Assignee: | Benjamin Eberlei |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Description |
|
The following class when value is set to false causes "Could not convert database value "b:0;" to Doctrine Type object" exception when loading the entity. /** @orm:Entity */
|
| Comments |
| Comment by Benjamin Eberlei [ 06/Dec/10 ] |
|
From the PHP manual about unserialize(): In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued.
The solution: Use NULL instead of false |
| Comment by Marcus Speight [ 06/Dec/10 ] |
|
But the string "b:0;" is unserializable it returns false. Also from the php manual on unserialize FALSE is returned both in the case of an error and if unserializing the serialized FALSE value. It is possible to catch this special case by comparing str with serialize(false) or by catching the issued E_NOTICE. I've submitted a pull request that handles it correctly. |
| Comment by Benjamin Eberlei [ 06/Dec/10 ] |
|
I know, but this type is called "object", so setting it to false makes no sense. Setting it to null makes sense though. I know that b:0; is false, but why do you set it to false anyways? Objects are either null or an instance of the object. Never false. |
| Comment by Marcus Speight [ 06/Dec/10 ] |
|
I'm storing settings in a database. using a Namespace, Key => Value triplet. I don't know what might be stored in the value part. Currently strings, NULL and boolean data are stored. Using object seem to be the best approach. (ArrayTypes have the same problem). If you think a different type would be better then please let me know. |
| Comment by Benjamin Eberlei [ 06/Dec/10 ] |
|
how is such a triplet only b:0; ? or is your entity the tripplet and the variable that fails is the value? |
| Comment by Marcus Speight [ 06/Dec/10 ] |
|
I've added my entity. The entity is the triplet. And it is the value that fails if false is stored. |
| Comment by Benjamin Eberlei [ 12/Dec/10 ] |
|
Although this should really be just array and object, not strange false types i added this patch to prevent future reports of this as a problem. The loosely typed language PHP can go with null or false, so why throw people stones in their way. |