Hi there,
Am Fr 10. Jul 2009, 08:00:55, JeremyMM schrieb:
Show quoted text> I am encountering Problems with PHP Session data if values are in the
> scientific notation style
> 1.0E+6
i made a few amendmends to PHP/Session/Serializer/PHP.pm so that it now
detects scientific notation. At least it works for me. I do know, that
the way i did it is most probably not the best/nicest/most elegant way
(i guess there is some cool way with sprintf to convert values in
scientific notation to a double), but it works for me and i am happy
with it.
maybe this piece of code is for some use for somebody and maybe that re
which i added in @re could be added to the module by the maintainer
'd:(-?\d+(?:\.\d+)?(?:E(?:\-|\+)\d)?);',
# double with scientific notation such as d:1.0E+6
jeremy
Index: PHP.pm
===================================================================
--- PHP.pm (revision 96)
+++ PHP.pm (revision 327)
@@ -238,7 +238,8 @@
'O:(\d+):', # object
'(N);', # null
'b:([01]);', # boolean
- '[Rr]:(\d+);', # reference count?
+ '[Rr]:(\d+);', # reference count?
+ 'd:(-?\d+(?:\.\d+)?(?:E(?:\-|\+)\d)?);', # double with scientific notation such as d:1.0E+6
);
sub parse {
@@ -270,7 +271,19 @@
$decoder->process_value($7);
}
elsif (defined $8) { # reference
- $decoder->process_value($8);
+ $decoder->process_value($8);
+ }
+ elsif (defined $9) { # double with scientific notation
+ my $val = $9;
+ if ($val =~ /(-?\d+(?:\.\d+)?)E(\-|\+)(\d)/) {
+ my ($double,$sign,$exp) = ($1,$2,$3);
+ if ($sign eq "-") { $exp = $exp*-1; }
+ my $val2 = $double*(10**($exp));
+ $decoder->process_value($val2);
+ }
+ else {
+ $decoder->process_value($9);
+ }
}
}