我们正在尝试执行以下 doctrine 查询及其抛出的 unserialize(): 偏移量 473 处的错误 578 字节。
教义查询:
SELECT p FROM MyCompanyBundle:Person p
WHERE p.dateOfExit IS NULL
AND (p.passportCountry IS NULL OR p.passportCountry <> :india OR
p.invitationId IS NOT NULL)
AND (p.category <> :category_cl AND
p.category <> :category_staff AND p.category <> :category_sev AND
p.category <> :category_visitor)
作为上述查询的一部分,它试图获取以下数据及其抛出错误。但同样适用于 mysql 查询。
Mysql 表输出
A:3:{s:19:"volunteering-local0";a:3:{s:8:"活动";s:23:"神秘之眼加尔各答2017";S:11:"描述";s:239:"我在引队,也在飞行小队,只有5个人,包括我。我们被告知要飞来飞去,向现场需要它的人伸出援手。大多数情况下,卑微的工作是我们的第一手责任。S:8:"位置";s:7:"加尔各答";}S:19:"志愿服务-本地1";a:3:{s:8:"活动";s:17:"内在工程";S:11:"描述";s:104:"我在入会日做志愿者。我也有机会成为厨房工作的一部分
详细的错误说明:
Symfony\Component\Debug\Exception\ 上下文错误异常 in vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php(第 58 行) ArrayType->convertToPHPValue('a:3:{s:19:"volunteering-local0";a:3:{s:8:"活动";s:23:"神秘之眼加尔各答2017";S:11:"描述";s:239:"我在引队,也在飞行小队,只有5个人,包括我。我们被告知要飞来飞去,向现场需要它的人伸出援手。大多数情况下,卑微的工作是我们的第一手责任。S:8:"位置";s:7:"加尔各答";}S:19:"志愿服务-本地1";a:3:{s:8:"活动";s:17:"内在工程";S:11:"描述";s:104:"我在入会日做志愿者。我也有机会成为厨房工作的一部分',对象(MySQL57Platform)) 在 vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator 中.php(第 316 行)
请向我提出任何解决这个教义问题的想法。
在你责怪 Doctrine ORM 之前,让我们先检查一下你的序列化数组。
序列化数组(基于您的 MySQL 表输出):
a:3:{s:19:"volunteering-local0";a:3:{s:8:"activity";s:23:"Mystic eye kolkata 2017";s:11:"description";s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";s:8:"location";s:7:"Kolkata";}s:19:"volunteering-local1";a:3:{s:8:"activity";s:17:"Inner Engineering";s:11:"description";s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too
等等,检查序列化数组有点混乱。让我们让它"可读":
a:3:{
s:19:"volunteering-local0";
a:3:{
s:8:"activity";
s:23:"Mystic eye kolkata 2017";
s:11:"description";
s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
s:8:"location";
s:7:"Kolkata";
}
s:19:"volunteering-local1";
a:3:{
s:8:"activity";
s:17:"Inner Engineering";
s:11:"description";
s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too
通过使序列化数组"可读",您可以在那里看到无效的序列化对象结构。
a:3:{
s:19:"volunteering-local0";
a:3:{
s:8:"activity";
s:23:"Mystic eye kolkata 2017";
s:11:"description";
s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
s:8:"location";
s:7:"Kolkata";
}
s:19:"volunteering-local1";
a:3:{
s:8:"activity";
s:17:"Inner Engineering";
s:11:"description";
s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too"; // you miss the closing double quote and semicolon
} // you miss the closing curly bracket
} // you miss the closing curly bracket
修复结构后,现在您在偏移误差方面遇到了麻烦。
第 1 行显示"a:3:value"。这意味着您有一个包含 3 个项目的数组。但是该值表示您里面只有 2 个项目(带有键"volunteering-local0"和"volunteering-local1")。所以第 1 行应该是"a:2:value"。
第 16 行显示"s:104:value"。这意味着您有一个正好包含 104 个字符的字符串。但是该值表示您只有 100 个字符的字符串。
如果你更深入地检查它,仍然有一些无效的结构。
序列化数组已损坏,或者说"无效"。这就是为什么 Doctrine 在尝试通过调用 "Doctrine\DBAL\Types\ArrayType::convertToPHPValue($serializedValue)" 将给定的序列化数组反序列化为 PHP 数组时引发异常的原因。即使您尝试使用 PHP 内部函数"unserialize($serializedValue)"对其进行反序列化,您也会陷入错误。它会说"unserialize():771 字节的偏移量 5 处出错"。
如果我必须更正它,我对基于您的序列化数组的原始 PHP 数组的想象将是:
array(
array(
'volunteering-local0' => array(
'activity' => 'Mystic eye kolkata 2017',
'description' => 'I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.',
'location' => 'Kolkata',
),
),
array(
'volunteering-local1' => [
'activity' => 'Inner Engineering',
'description' => 'I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too',
],
],
]
如果我想要该 PHP 数组的序列化数组,它将是:
a:2:{
i:0;
a:1:{
s:19:"volunteering-local0";
a:3:{
s:8:"activity";
s:23:"Mystic eye kolkata 2017";
s:11:"description";
s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
s:8:"location";
s:7:"Kolkata";
}
}
i:1;
a:1:{
s:19:"volunteering-local1";
a:2:{
s:8:"activity";s:17:"Inner Engineering";
s:11:"description";
s:100:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too";
}
}
}
如果我想要该序列化数组的单行,它将是:
a:2:{i:0;a:1:{s:19:"volunteering-local0";a:3:{s:8:"activity";s:23:"Mystic eye kolkata 2017";s:11:"description";s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";s:8:"location";s:7:"Kolkata";}}i:1;a:1:{s:19:"volunteering-local1";a:2:{s:8:"activity";s:17:"Inner Engineering";s:11:"description";s:100:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too";}}}