Skip to content

Loading…

DBAL-73: Could not convert database value "b:0;" to Doctrine Type object #1955

Closed
doctrinebot opened this Issue · 9 comments

2 participants

@doctrinebot

Jira issue originally created by user wizbit:

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 /
class MyClass
{
/
**
* @orm:Column(name="value", type="object")
*/
public $value;
}

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by wizbit:

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.

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by wizbit:

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.

@doctrinebot

Comment created by @beberlei:

how is such a triplet only b:0; ? or is your entity the tripplet and the variable that fails is the value?

@doctrinebot

Comment created by wizbit:

I've added my entity. The entity is the triplet. And it is the value that fails if false is stored.
It allows me to store the value(false) but the throws an exception on loading the entity. It should allow the loading of the value(false) or disallow the storing of a false value.

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC5 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.