php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52286 New lines in serialize()
Submitted: 2010-07-08 11:39 UTC Modified: 2010-07-08 11:48 UTC
From: paydorrr at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.3.2 OS: Ubuntu
Private report: No CVE-ID: None
 [2010-07-08 11:39 UTC] 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!";}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-08 11:48 UTC] paydorrr at gmail dot com
-Status: Open +Status: Closed
 [2010-07-08 11:48 UTC] 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.
 [2013-01-03 13:58 UTC] live dot to dot ride at seznam dot cz
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC