I have this code below to insert serialized data in a field (order_pictures):
$pictures_id = unserialize($category->getOrderPictures());
array_push($pictures_id, $picture->getId());
$category->setOrderPictures(serialize($pictures_id));
It works ok the first time I execute it. At least, it stores b:0; in the order_pictures field.
But when I execute it again, the value of $pictures_id is bool(false), and I expected an array type.
Any idea?
Regards
Javi
Your problem is that you’re trying to
unserializethe contents of$category->getOrderPictures()before it’s ever been initialized, so$pictures_idis getting booleanfalsein it, which is the result ofunserializefailing. Then thearray_push()is failing because$pictures_idisn’t an array.Try this: