Skip Menu |

This queue is for tickets about the PHP-Serialization CPAN distribution.

Report information
The Basics
Id: 42029
Status: resolved
Priority: 0/
Queue: PHP-Serialization

People
Owner: Nobody in particular
Requestors: gregs [...] net-virtual.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug in PHP::Serialization
Date: Mon, 29 Dec 2008 14:24:47 -0800 (PST)
To: bug-PHP-Serialization [...] rt.cpan.org
From: "Greg Saylor" <gregs [...] net-virtual.com>
Hello, The following code does not generate something PHP's unserialize can parse: ======================= use PHP::Serialization qw(serialize unserialize); use Data::Dumper; my $hash = { 'Volkswagen' => { 'Touareg' => { '2.5' => 1 } }, }; my $str = serialize($hash); print $str; ======================= The string generated is "a:1:{s:10:"Volkswagen";a:1:{s:7:"Touareg";a:1:{d:2.5;i:1;}}}", I think the issue is that it is encoding "2.5" as a double 'd:2.5' and it should be a string 's:3:2.5'. Regards, Greg Saylor
Subject: [rt.cpan.org #42029]
Date: Mon, 29 Dec 2008 16:03:39 -0800 (PST)
To: bug-PHP-Serialization [...] rt.cpan.org
From: "Greg Saylor" <gregs [...] net-virtual.com>
Thought this might be helpful too: bash$ php -r '$arr = array("Volkswagen" => array ("Touareg" => array ("2.5" => 1)));print serialize($arr);' a:1:{s:10:"Volkswagen";a:1:{s:7:"Touareg";a:1:{s:3:"2.5";i:1;}}} It appears PHP indeed declares it as 's:3:"2.5"'. - Greg
Yup, that's definitely a bug, because there can be only integer and string indexes in php arrays. I've attached a patch to fix it.
322c322,323 < my ($self, $val) = @_; --- > my ($self, $val,$iskey) = @_; > $iskey=0 unless defined $iskey; 334c335 < elsif ( $val =~ /^-?\d+\.\d*$/ ) { --- > elsif ( $val =~ /^-?\d+\.\d*$/ && !$iskey) { 379,380c380,382 < foreach ( %{$val} ) { < $buffer .= $self->encode($_); --- > while ( my ($key, $value) = each(%{$val}) ) { > $buffer .= $self->encode($key,1); > $buffer .= $self->encode($value);
Fixed in the just shipped 0.32