#18662 [Bgs->Csd]: unserialize returns false if some element is empty
| From: | to at andybutkaj dot com | Date: | Fri, 02 Aug 2002 10:05:14 +0000 |
| Subject: | #18662 [Bgs->Csd]: unserialize returns false if some element is empty | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15799@lists.php.net to get a copy of this message | ||
ID: 18662
User updated by: to@andybutkaj.com
Reported By: to@andybutkaj.com
-Status: Bogus
+Status: Closed
Bug Type: Strings related
Operating System: Windows 2000 and Windows XP
PHP Version: 4.2.2
New Comment:
Please read, read, read solid and properly SNIPER, i still talking
about helpful (maybe not for you) differences between earlier versions
of php and actual versions.
It is not a PHP problem? Pleas try read two times, before you something
write. Everybody knows it is Jscript error.
Thank you nohn@php.net for serious interest about.
Previous Comments:
------------------------------------------------------------------------
[2002-08-02 05:41:31] sniper@php.net
Fix your jscript. Not PHP problem.
------------------------------------------------------------------------
[2002-08-02 03:52:28] to@andybutkaj.com
Client side function to serialize an array [JScript]:
1 function serialize (toSerialize)
2 {
3 var fill = '';
4
5 /** chcek argument type */
6 var argType = typeof (toSerialize);
7
8 /** decide by type, how to serialize */
9 if (argType == 'number')
10 return 'i:' + toSerialize + ';';
11 else if (argType == 'boolean')
12 return 'b:' + (toSerialize == true ? '1' : '0') +
';';
13 else if (argType == 'string')
14 {
15 /** check if string doesn't be repesented as number */
16 if (!isNaN (toSerialize))
17 return 'i:' + toSerialize + ';';
18 else
19 return 's:' + toSerialize.length + ':"' + toSerialize +
'";';
20 }
21 else if (argType == 'object')
22 {
23 /** serialize object usualy array */
24 var noItems = 0
25 for (var i in toSerialize)
26 {
27 var itemKey = serialize (i);
28 var itemValue = serialize (toSerialize [i]);
29
30 fill += itemKey + itemValue;
31 noItems = noItems + 1;
32 }
33 fill = 'a:' + noItems + ':{' + fill + '}';
34 }
35
36 /** return serialized string */
37 return fill;
38 }
___________________________________________________________
Making an array at client-side (JScript).
if (save_array[i] != "undefined") {
save_array[i] = new Array();
save_array[i]["mkey_index"] = new Array();
save_array[i]["save_type"] = new Array();
save_array[i]["integer"] = new Array();
}
save_array[i]["mkey_index"] = text; // some text
save_array[i]["save_type"] = integer; // 1
save_array[i]["integer"] = empty_string; // ''
___________________________________________________________
Server-side (PHP 4.0.6):
JScript serialized string we can unserialize with php 4.0.6 without
lost any information and array looks like this:
array (0 => array("mkey_index" => "some text", "save_type" =>
1,
"integer" => 0), ...);
So you can see this:
Part of a serialized string 'i:;' is after unserialize under php406
INTEGER VALUE 0!;
___________________________________________________________
Server-side 4.2.2:
Unserialize return bool(false), unserialize "crashed" on sequence 'i:;'
in serialized string (correct work).
___________________________________________________________
Client side function 'patch': (JScript)
Above (line 17):
I changed this line this way to correct serialize in JScript:
17 return (toSerialize == '') ? 's:0:"";' : 'i:' +
toSerialize +
';';
PHP422 returns an array with empty string now.
------------------------------------------------------------------------
[2002-08-02 02:56:43] nohn@php.net
You don't need to give your full Arrays. What we need is a working
example.
------------------------------------------------------------------------
[2002-08-01 19:46:06] to@andybutkaj.com
i cannot attach full example, it is client-server communication, where
client make the serialized string in php rules for php. Serialized
string in earlier versions of php (e.g 4.0.6) may contain wrong
sequenction (i:; what mean integer with nothing value), while this
version (4.2.2) dont support this. You cannot make php serialized
string with something like this, integer is followed by number always.
Everything what i wanted is explain the differences. When i was
opening the bug i dont know them.
(i think it is helpful)
For me, it is more bug for earlier version than bug for this version
php. My question is, can i close the status? This is no bug for me
anymore...
------------------------------------------------------------------------
[2002-07-31 18:08:49] sniper@php.net
Please attach the full example, in which you serialize and unserialize
the variables. Just adding some random, supposedly serialized string is
not very helpful.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/18662
--
Edit this bug report at http://bugs.php.net/?id=18662&edit=1