Bug #52286 [Com]: New lines in serialize()
Edit report at https://bugs.php.net/bug.php?id=52286&edit=1
ID: 52286
Comment by: live dot to dot ride at seznam dot cz
Reported by: paydorrr at gmail dot com
Summary: New lines in serialize()
Status: Closed
Type: Bug
Package: Arrays related
Operating System: Ubuntu
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
I had the same problem when I uploaded the source code to the git repository. Git transfers newlines
to different form (\n \r\n ). Json_decode / encode solves it right. http://stackoverflow.com/a/2662338
Previous Comments:
------------------------------------------------------------------------
[2010-07-08 11:48:22] paydorrr at gmail dot com
My example actually has an error in it and works perfectly fine.
Actually I had the problem as I posted the string to serialize to the test page.
I will try to reproduce that and post it again.
------------------------------------------------------------------------
[2010-07-08 11:39:44] paydorrr at gmail dot com
Description:
------------
I just hit an unexpected problem:
serialize() counts new lines as characters, although in the serialized output, those characters do
not appear. The character count of the serialized string is then wrong and unserialize() ist not
possible.
Test script:
---------------
$textOne = "String to serialize with
multiple
lines!";
$array = Array(0 => $textOne);
echo serialize($array);
/*
This will print out:
a:1:{i:0;s:42:"String to serialize with multiple lines!";}
The problem with that is, that the serialized String is actually 40, not 42 characters long. Because
of that, you cannot unserialize the whole serialized Array. */
Expected result:
----------------
a:1:{i:0;s:40:"String to serialize with multiple lines!";}
Actual result:
--------------
a:1:{i:0;s:42:"String to serialize with multiple lines!";}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52286&edit=1
Thread (3 messages)