#18662 [Opn->Fbk]: unserialize returns false if some element is empty
| From: | sniper@php.net | Date: | Wed, 31 Jul 2002 22:08:50 +0000 |
| Subject: | #18662 [Opn->Fbk]: unserialize returns false if some element is empty | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15721@lists.php.net to get a copy of this message | ||
ID: 18662
Updated by: sniper@php.net
Reported By: to@andybutkaj.com
-Status: Open
+Status: Feedback
Bug Type: Strings related
Operating System: Windows 2000 and Windows XP
PHP Version: 4.2.2
New Comment:
Please attach the full example, in which you serialize and unserialize
the variables. Just adding some random, supposedly serialized string is
not very helpful.
Previous Comments:
------------------------------------------------------------------------
[2002-07-31 08:14:42] to@andybutkaj.com
sorry, my serialized array is not correct (i edit this array to not to
be so long), your example work for me, but still some differences in
work with serialized string
I found this in serialized string.
php 4.0.6
...array_key;s:3:"txt" -> serialized string - work
...array_key;s:0:"" -> string withour value - work
...array_key;i:1; -> serialized integer - work
...array_key;i:; -> integer without value - work
php 4.2.2
...array_key;s:3:"txt" -> serialized string - work
...array_key;s:0:"" -> string withour value - work
...array_key;i:1; -> serialized integer - work
...array_key;i:; -> integer without value - FALSE
this correspond to this unworking array (4.2.2), working (4.0.6) with
integer without values:
a:1:{s:3:"fas";a:6:{s:10:"mkey_index";s:3:"fas";s:9:"save_type";i:1;s:
6:"German";i:;s:7:"English";i:;s:6:"Slovak";i:;s:5:"Czech";i:;}}
___________________________________________________________
I don't know if this is bug, now. I can't create this array with
declaration array( ... ). In strict rules it is not bug, it is correct
work.
Only backwards compatibility maybe.
Thank you for solve this problem!
------------------------------------------------------------------------
[2002-07-31 07:03:37] nohn@php.net
Could verify this with PHP 4.3.0-dev 2002-07-31 on Compaq Tru64:
$test_array =
'a:1:{s:12:"fas";a:6:{s:10:"mkey_index";s:12:"fas";s:9:"save_typ
e";i:1;s:6:"German";i:;s:7:"English";i:;s:6:"Slovak";i:;s:5:"Czech";i:;}}';
$result_array = unserialize($test_array);
print_r($result_array);
Returns nothing.
On the same machine this works:
$array = array(1,2,3,9,7,4,5,12,"lala"=>array("test"=>1,2,3,3));
$serialized_array = serialize($array);
print_r($serialized_array);
$result_array = unserialize($serialized_array);
print_r($array);
print_r($result_array);
Results as expected in:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 9
[4] => 7
[5] => 4
[6] => 5
[7] => 12
[lala] => Array
(
[test] => 1
[0] => 2
[1] => 3
[2] => 3
)
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 9
[4] => 7
[5] => 4
[6] => 5
[7] => 12
[lala] => Array
(
[test] => 1
[0] => 2
[1] => 3
[2] => 3
)
)
Are you shure, your serialized Array is correct?
------------------------------------------------------------------------
[2002-07-31 06:30:37] to@andybutkaj.com
I try unserialize array and everything goes nice when the array has all
elements filled. When one of element is empty unserialize returns
false
More specific:
PHP 4.0.6
"""""""""
a:1:{s:12:"fas";a:6:{s:10:"mkey_index";s:12:"fas";s:9:"save_type";i:1;s:6:"German";i:;s:7:"English";i:;s:6:"Slovak";i:;s:5:"Czech";i:;}}
unserialize returns array where empty elements are replaced by 0
___________________________________________________________
PHP 4.2.2
"""""""""
a:1:{s:12:"fas";a:6:{s:10:"mkey_index";s:12:"fas";s:9:"save_type";i:1;s:6:"German";i:;s:7:"English";i:;s:6:"Slovak";i:;s:5:"Czech";i:;}}
unserialize returns false (if no empty elements, unserialize returns
correct array)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18662&edit=1