Subject: | PHP 5.3+ namespaces get wrong class when serialized |
ie:
my $data = unserialize(q|O:7:"Foo\\Bar":1:{s:5:"value";i:1;}|); # ref $data eq 'PHP::Serialization::Object::Foo\\Bar'
$data = unserialize( serialize($data) ); # ref $data eq 'PHP::Serialiation::Object::Bar'
test and patch attached.
Subject: | 11namespaces.t |
#!/usr/bin/env perl
use Test::More tests => 1;
use PHP::Serialization qw(unserialize serialize);
my $encoded = q|O:7:"Foo\\Bar":1:{s:5:"value";i:1;}|;
my $data = unserialize($encoded);
is( ref $data, ref unserialize( serialize( $data )) );
Subject: | Serialization.pm.diff |
diff --git a/PHP/Serialization.pm b/PHP/Serialization.pm
index 9dc3120..59a57c6 100644
--- a/PHP/Serialization.pm
+++ b/PHP/Serialization.pm
@@ -449,7 +449,8 @@ sub _encode {
}
elsif ( $type eq 'obj' ) {
my $class = ref($val);
- my $subclass = (split "::", $class)[-1];
+ $class =~ /(\w+)$/;
+ my $subclass = $1;
$buffer .= sprintf('O:%d:"%s":%d:', length($subclass), $subclass, scalar(keys %{$val})) . '{';
foreach ( %{$val} ) {
$buffer .= $self->encode($_);