Subject: | Serialization of booleans |
Date: | Tue, 14 Apr 2009 11:12:48 +0300 |
To: | bug-PHP-Serialization [...] rt.cpan.org |
From: | Teodor Milkov <zimage [...] icdsoft.com> |
Hi,
We noticed that current versions of PHP::Serialization return 0 instead
of undef for boolean data. In the following example:
#!/usr/bin/perl
use PHP::Serialization;
use Data::Dumper;
$s = 'a:4:{i:0;s:3:"ABC";i:1;s:3:"OPQ";i:2;s:3:"XYZ";i:3;b:0;}';
$u = PHP::Serialization::unserialize($s);
print(Dumper($u));
we got the following output:
$VAR1 = [
'ABC',
'OPQ',
'XYZ',
0
];
Isn't it supposed to be:
$VAR1 = [
'ABC',
'OPQ',
'XYZ',
undef
];
Looks like the following patch is needed:
--- lib/PHP/Serialization.pm 2004-02-23 16:48:40.000000000 -0500
+++ lib/PHP/Serialization.pm 2007-05-29 03:12:06.000000000 -0400
@@ -231,6 +231,9 @@
# Ok, read our boolen value..
my $bool = $self->_readchar();
$self->_skipchar(); # Toss the seperator
+ if ($bool eq '0') {
+ $bool = undef;
+ }
push(@elems,$bool);
} elsif ( $type eq 'undef' ) {
# Ok, undef value..
--
Theodor Milkov ICDSoft Ltd.
System Administrator http://www.icdsoft.com/
Message body not shown because it is not plain text.