Arrays are often serialized so that they can be stored in a database text field. If you change the data within a serialized array, without changing the character count, you will get the error above.
For example take this code:
Code: Select all
<?php
$thing = array('one','two');
echo serialize($thing);
?>
This will echo out the following:
a:2:{i:0;s:3:”one”;i:1;s:3:”two”;}
Now… if you stored that in a database, you could then retrieve it later and unserialize() it to get your array back. wohoo!
In that serialized data, s:3:”one” means that the first element in the array is a string, and that it’s 3 characters long. Now.. if you manually changed “one” to “otherone” like this
a:2:{i:0;s:3:”otherone”;i:1;s:3:”two”;} then when you ran it through unserialize() to retrieve your array, you would get the error were talking about.
Fix: To correct this you would need to update the string length also like so:
a:2:{i:0;s:8:”otherone”;i:1;s:3:”two”;} because “otherone” is actually 8 characters long.
Point is, the string in the field is malformed;) It needs to replaced.