Skip to Content »

FlashApe » Sending Negative Integers through AMFPHP

 Sending Negative Integers through AMFPHP

  • April 11th, 2008
  • 12:55 pm

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:
  1. function readAmf3Int()
  2.     {
  3.         $res = 0;
  4.         $int = $this->readByte();
  5.        
  6.         if($int <128) {
  7.             return $int;
  8.         } else {
  9.             $int = ($int & 0x7f) <<7;
  10.            
  11.             $tmp = $this->readByte();
  12.            
  13.             if($tmp <128) {
  14.                 $int |= $tmp;
  15.             }else{
  16.                 $int = ($int | ($tmp & 0x7f)) <<7;
  17.                 $tmp = $this->readByte();
  18.                 if($tmp <128){
  19.                     $int |= $tmp;
  20.                 }else{
  21.                     $int = ($int | ($tmp & 0x7f)) <<8;
  22.                     $tmp = $this->readByte();
  23.                     $int |= $tmp;
  24.                 }
  25.             }
  26.         }
  27.  
  28.         $mask = 1<<28;
  29.         $res = -($int & $mask) | $int;
  30.  
  31.         return $res;
  32.     }

4 People had this to say...

Gravatar
  • Evgeniy
  • May 8th, 2008
  • 9:38 pm

Thank's for this!

Gravatar
  • Ramon
  • October 6th, 2008
  • 1:12 am

Really useful !!!

Thanks.

Gravatar
  • Gary
  • November 28th, 2008
  • 1:14 am

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!

Gravatar
  • Oliver
  • February 9th, 2009
  • 7:08 am

Anyone experiencing this with Zend_Amf too? We do.

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>