Rich Rodecker’s blog on flash, flex, actionscript, javascript, and php, with a dash of randomness
Sending Negative Integers through AMFPHP
There is a weird bug in AMFPHP regarding sending negative integers. If you try and send a number such as -87, it shows up as 4294967209 in php. I did some digging and found on the amfphp forums that it has to do with amfphp's readAmf3Int() method in AMFDeserialzer.php. Here is the updated function that was posted on the forum:
PHP:
-
function readAmf3Int()
-
{
-
$res = 0;
-
$int = $this->readByte();
-
-
if($int <128) {
-
return $int;
-
} else {
-
$int = ($int & 0x7f) <<7;
-
-
$tmp = $this->readByte();
-
-
if($tmp <128) {
-
$int |= $tmp;
-
}else{
-
$int = ($int | ($tmp & 0x7f)) <<7;
-
$tmp = $this->readByte();
-
if($tmp <128){
-
$int |= $tmp;
-
}else{
-
$int = ($int | ($tmp & 0x7f)) <<8;
-
$tmp = $this->readByte();
-
$int |= $tmp;
-
}
-
}
-
}
-
-
$mask = 1<<28;
-
$res = -($int & $mask) | $int;
-
-
return $res;
-
}
| Print article | This entry was posted by rich on April 11, 2008 at 12:55 pm, and is filed under Flex, php. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 5 years ago
Thank's for this!
about 4 years ago
Really useful !!!
Thanks.
about 4 years ago
Thanks for sharing your solution, I thought I was going crazy when -1 in flex ended up as 4294967295 in my amfphp service. I was almost at the point of resorting to storing numbers as text!
about 4 years ago
Anyone experiencing this with Zend_Amf too? We do.
about 3 years ago
Thank you!!
I've been pulling my hair out all morning trying to get to the bottom of this.
about 3 years ago
Thank you!
about 2 years ago
Hey, thanks for this. I thought I was going crazy.
Have you tried this new function? Does it work properly? I gotta admit I'm a little scared to muck with the inner workings of AMFPHP this way...
about 2 years ago
Yes, it worked when I wrote the post. I believe that since that, other developers have picked up the AMFPHP project and done some work on it, so I'm not sure if it still applies. Only one way to find out for sure
about 1 year ago
Nice work, thanks!