|
From: Jesse M. <jma...@az...> - 2007-03-27 08:02:36
|
>From looking at Protocol.php:
function readLong(){
// Thanks Radu-Adrian Popescu
$data = unpack('N2', $this->read(8));
$value = $data[1]*256*256*256*256 + $data[2]; // +0.0;
return $value;
}
This looks a little suspicious: It's trying to build essentially a double
from 2 signed integers. It seems extra strange when the long 1174970145000L
comes over the wire as: $data[1] = 273, $data[2] = -1850894104 .
I wrote some pretty longwinded int to double code by unpacking the bytes:
function readLong(){
// Thanks Radu-Adrian Popescu
$data = unpack('N2', $this->read(8));
$h = $data[1];
$l = $data[2];
$b[] = ($h >> 24) & 0xff;
$b[] = ($h >> 16) & 0xff;
$b[] = ($h >> 8) & 0xff;
$b[] = $h & 0xff;
$b[] = ($l >> 24) & 0xff;
$b[] = ($l >> 16) & 0xff;
$b[] = ($l >> 8) & 0xff;
$b[] = $l & 0xff;
$m = 1.0;
$value = 0.0;
for ($i = 0 ; $i != 8 ; $i++) {
$value += $b[7 - $i] * $m;
$m *= 256.0;
}
return $value;
}
It seems pretty longwinded way of putting together a double, but it does
work (at least for my example -- no big testing done yet). There's no doubt
a shorter way of manipulating stuff, but it seems tricky since you need to
go from an int to a double.
--jesse
On 3/26/07, Jesse Macnish <jma...@az...> wrote:
>
> I'm having a problem with sending a Date over the wire from Java to
> PHP using Hessian 1.0.5RC2. From the java side:
>
> millis: 1174970145000 (Mon Mar 26 21:35:45 PDT 2007)
>
> Is getting turned into a DateTime on the PHP side of:
>
> DateTime Object
> (
> [day] => 05
> [month] => 02
> [year] => 2007
> [hour] => 03
> [minute] => 32
> [second] => 57
> [_timestamp] => 1170675177.704
> [weekDay] => 1
> )
>
> Simple test:
>
> public Date testDate() {
> Date d = new Date(1174970145000L);
> logger.info("Date:" + d);
> return d;
> }
>
> Output: Date:Mon Mar 26 21:35:45 PDT 2007
>
> $res = $question_proxy->testDate();
> pre_print($res);
>
> Output: 2007-02-05 03:32:57
>
|