[英]“Array to string conversion” error when using hash in Document
I'm attempting to use the hash type for a Document. 我正在尝试使用文档的哈希类型。 When I'm creating an object there isn't a problem, but the moment I attempt to retrieve a document, I get an "Array to string conversion".
当我创建一个对象时没有问题,但是当我尝试检索文档时,我得到一个“数组到字符串转换”。
I've simplified the document. 我简化了文件。 This Array to string conversion only started occurring when I added this hash property.
仅当我添加此哈希属性时才开始发生此数组到字符串转换。
Looking at symfony's dump messages, it seems to be coming from the hydrator. 看看symfony的转储消息,它似乎来自保湿器。
Any ideas why Doctrine is attempting to convert the data to a string? Doctrine试图将数据转换为字符串的任何想法?
class MyDocument
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\Field(type="hash")
*/
protected $value = array();
}
Somewhere in one of my services: 在我的一项服务中的某个地方:
$product =
$this->container->get('doctrine_mongodb')
->getRepository('XTradBundle:Traduction')
->findAll();
Stack Trace: 堆栈跟踪:
in var\cache\dev\doctrine\odm\mongodb\Hydrators\WeBSurgTradBundleDocumentTraductionHydrator.php at line 84 -
if (isset($data['value']) || (! empty($this->class->fieldMappings['value']['nullable']) && array_key_exists('value', $data))) {
$value = $data['value'];
if ($value !== null) {
//Why is it converting it to a string here?
$return = (string) $value;
} else {
$return = null;
}
Would seem that $value
in protected $value = array();
似乎
$value
in protected $value = array();
is a reserved name. 是保留名称。 Simply naming it to something else solved the problem.
简单地将其命名为其他东西可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.