I try to serialize object data to be saved into a file by php using serialize package by PHP.js.
Chrome: fine FF: fine IE9: fine IE9 in compatibility mode (essentially IE7): not fine.
Error from console:
SCRIPT5022: Exception thrown and not caught
serialize.min.js, line 144 character 55
Serialized the data basically looks like this:
a:180:{s:40:"Aleksis Kiven tie 15<br>04200 Kerava<br>";a:2:{i:0;d:60.4012598;i:1;d:25.09659910000005;}
Unserialized:
{"Aleksis Kiven tie 15<br>04200 Kerava<br>": [60.4012598, 25.09659910000005]}
Javascript that handles the caching looks like this:
function saveCache(data) {
sdata = serialize(data);
$.ajax({
type: 'POST',
url: 'http://localhost/foobar/files/coordinates.php',
data: {
'do': 'write',
'data': sdata
}
});
}
I'm caching geocoding results by address into a text file.
Please ask more if I'm not making sense.
MAJOR EDIT: I corrected the examples as pointed out. Also the major thing is that the issue really changed; it isn't actually an issue with serialize(), but with unserialize().
I figured it out myself after all.
When I took a closer look it wasn't serialize() after all that caused the error but rather unserialize() which is in the same package with me.
At some point the cache went corrupt and for some reason IE9 in comp-mode was the only browser of those I tested that didn't tolerate it. The reason for the cache corrupting was stacking utf8_encodes/decodes that started messing things up.
It went like this:
The solution lies in unserialize() performing an unnecessary utf8_decode(). The page is UTF-8. All my javascript files are UTF-8. The cached data is made many times sure to be UTF-8. So there souldn't be and isn't any reason to decode UTF-8. I'm not a 100% sure how exactly this crapped out the data, but commenting out the utf8_decode solved the issue.
I'm a little bit disappointed in the error tolerance of modern browsers. It is too high. But well, good thing I figured it out.