Reputation: 2167
I have this string saved in database, using Doctrine's array type.
$test = unserialize('a:10:{s:4:"data";s:12:"registration";s:5:"order";s:4:"desc";s:5:"mySex";i:2;s:3:"sex";s:3:"all";s:6:"ageMin";i:36;s:6:"ageMax";i:46;s:9:"interests";O:43:"Doctrine\Common\Collections\ArrayCollection":1:{s:53:"Doctrine\Common\Collections\ArrayCollectionelements";a:1:{i:0;O:41:"Singles\Bundle\UserBundle\Entity\Interest":4:{s:45:"Singles\Bundle\UserBundle\Entity\Interestid";N;s:50:"Singles\Bundle\UserBundle\Entity\Interestprofile";N;s:46:"Singles\Bundle\UserBundle\Entity\Interestsex";i:1;s:51:"Singles\Bundle\UserBundle\Entity\Interestactivity";i:0;}}}s:14:"onlyWithPhotos";b:1;s:8:"counties";N;s:9:"districts";N;}');
It always throws an exception with message:
Notice: unserialize(): Error at offset 261 of 615 bytes
That is exactly the semicolon at end of this string:
... Doctrine\Common\Collections\ArrayCollectionelements";
What could cause the deserialization to fail? Whenever I exclude the array collection, deserialization works. The serialization is done using doctrine, I don't do it manually.
Upvotes: 0
Views: 618
Reputation: 4244
Output of serialize
is binary string, which can contain null bytes
– eg \x00
. Deserialization fails because of you are passing string trimmed of that null bytes
, so string size of FQCN doesn't match. Eg:
-> Size is set to 53:
-> …ArrayCollection":1:{s:53:"Doctrine\Common\C…
-> But it is 51:
-> …ArrayCollection":1:{s:51:"Doctrine\Common\C…
Upvotes: 1